-
-
Notifications
You must be signed in to change notification settings - Fork 92
Description
When using triggerServerCallback from the TypeScript/JavaScript wrapper, the callback handler crashes with TypeError: Cannot read properties of null (reading '0') when the server-side callback returns nil/null.
Affected File
client/resource/callback/index.js (line 34)
Current Code (Buggy)
pendingCallbacks[key] = (args) => {
if (args[0] === 'cb_invalid') // ❌ Crashes if args is null
reject(callback '${eventName} does not exist);
resolve(args);
};
Proposed Fix
pendingCallbacks[key] = (args) => {
if (args && args[0] === 'cb_invalid') // ✅ Null-safe check
reject(callback '${eventName} does not exist);
resolve(args);
};
Steps to Reproduce
-
Create a server-side callback that returns nil:
lib.callback.register('test:callback', function(source)
return nil -- Returns nil when no data exists
end) -
Call it from TypeScript/JavaScript client:
import { triggerServerCallback } from '@communityox/ox_lib/client';
const result = await triggerServerCallback('test:callback', 5000);
- Error occurs: TypeError: Cannot read properties of null (reading '0')
Expected Behavior
The callback should gracefully handle null returns and resolve with null instead of crashing.
Environment
- Package Version: 3.32.1
- FiveM Server: Latest
- Build Tool: esbuild
Impact
This is a critical bug that causes crashes in any resource using callbacks that may return null, which is common for database queries that find no results or optional data lookups.
Additional Notes
The Lua version of ox_lib handles nil returns correctly. This is only an issue in the JS/TS NPM package where the callback response handler doesn't check if args exists before accessing args[0].