fix(database): throw Error before creating promise

Promises, even when resolved/rejected immediately after their creation, will
destroy any useful information from a stack trace when used over
events/exports.

Since some people still use the exports rather than MySQL/lib.lua, and for
some reason don't know the correct syntax for Lua exports (i.e. using
exports.oxmysql.query instead of the CORRECT exports.oxmysql:query) it's
comically common for an "untraceable" error to get spit out.

Will this help? No. Will everyone expect me to solve their issues? Yes.

Go update your scripts to use MySQL/lib.lua and we can all get along
stress-free.
This commit is contained in:
Linden committed 2022-11-18 08:58:43 +11:00
1 parent 30e37af313
commit 5a949b9546
3 files changed
+24 -14

No files matched your search

+9 -4
View File
@@ -6,7 +6,7 @@ import type { CFXCallback, CFXParameters } from '../types';
import type { QueryType } from '../types';
import { scheduleTick } from '../utils/scheduleTick';
export const rawQuery = async (
export const rawQuery = (
type: QueryType,
invokingResource: string,
query: string,
@@ -14,12 +14,17 @@ export const rawQuery = async (
cb?: CFXCallback,
throwError?: boolean
) => {
if (!serverReady) await waitForConnection()
if (typeof query !== 'string')
throw new Error(
`${invokingResource} was unable to execute a query!\nExpected query to be a string but received ${typeof query} instead.`
);
scheduleTick();
[query, parameters, cb] = parseArguments(invokingResource, query, parameters, cb);
scheduleTick();
return new Promise(async (resolve, reject) => {
if (!serverReady) await waitForConnection();
return await new Promise((resolve, reject) => {
pool.query(query, parameters, (err, result, _, executionTime) => {
if (err) return reject(err);