{"record":{"id":"a8918bfdbd46c9da","repo":"amark/gun","slug":"missing-callback","errorCode":null,"errorMessage":"Missing Callback","messagePattern":"Missing Callback","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/ison.js","lineNumber":669,"sourceCode":" * @return { number }\n */\nlet validateIntensity = (intensity) => {\n  intensity = Math.round(intensity);\n  if (intensity > 0 && intensity <= 32)\n    return intensity;\n  else if (intensity <= 0)\n    return 1;\n  else\n    return 32;\n};\n\nyson.parseAsync = function (data, callback, reviver = null, intensity = 1) {\n\t//Bring parity with the in-built parser, that takes both string and buffer\n\tif (Buffer.isBuffer(data))\n\t\tdata = data.toString();\n\n\tif (!callback)\n\t\tthrow new Error('Missing Callback');\n\n\n  intensity = validateIntensity(intensity);\n\treturn parseWrapper(data, reviver, intensity, callback);\n};\n\n  /**\n  * Error checking  and call of appropriate functions for JSON stringify API\n  * @param { primitive data types } data\n  * @param { function or array } replacer\n  * @param { number or string } space\n  * @param { number } intensity\n  * @param { function } callback\n  * @return { function } stringifyWrapper\n  */\nyson.stringifyAsync = function(data, callback, replacer = null, space, intensity = 1) {\n  if (typeof callback !== 'function') {\n    throw new TypeError('Callback is not a function');","sourceCodeStart":651,"sourceCodeEnd":687,"githubUrl":"https://github.com/amark/gun/blob/552227599d47ba0493824b7fcf8a00c8cd6404ba/lib/ison.js#L651-L687","documentation":"yson.parseAsync is the asynchronous analogue of JSON.parse for Gun's yson parser. Because parsing happens asynchronously (chunked/deferred), the result cannot be returned synchronously — the library requires a callback to deliver the result or error, and throws immediately (synchronously) if no callback was supplied.","triggerScenarios":"Calling yson.parseAsync(data) or yson.parseAsync(data, null) with the second (callback) argument missing, undefined, or explicitly null. Note any falsy value (including '' or 0) triggers the throw — unlike stringifyAsync this is a truthiness check, not a typeof 'function' check.","commonSituations":"Migrating code from synchronous JSON.parse where no callback was needed; forgetting the callback when converting from yson.parse; passing an optional reviver without realizing the callback argument sits before it in the signature (data, callback, reviver, intensity); results of optional-chained lookups being undefined at runtime.","solutions":["Pass a function as the second argument: yson.parseAsync(data, (err, res) => { ... })","Check the argument order — callback comes immediately after data, before reviver and intensity","If you do not need async, use the synchronous parser directly (JSON.parse or yson's sync API)","Fix any code path where the callback variable is conditionally undefined before the call"],"exampleFix":"// before\nconst obj = yson.parseAsync(str, null);\n// after\nyson.parseAsync(str, (err, obj) => {\n  if (err) return console.error(err);\n  console.log(obj);\n});","handlingStrategy":"type-guard","validationCode":"function canParseAsync(data, cb) {\n  return typeof cb === 'function';\n}\nif (!canParseAsync(str, myCallback)) throw new Error('parseAsync requires a callback');","typeGuard":"const isFn = (v) => typeof v === 'function';\nif (!isFn(cb)) throw new TypeError('callback must be a function');","tryCatchPattern":"try {\n  yson.parseAsync(data, (err, res) => { if (err) throw err; use(res); });\n} catch (e) {\n  // synchronous throw: missing/invalid callback\n  console.error('parseAsync setup failed:', e.message);\n}","preventionTips":["Always pass a callback as the 2nd argument to parseAsync","Remember the signature order: (data, callback, reviver, intensity)","Use an editor snippet/lint rule flagging parseAsync calls with fewer than 2 arguments"],"tags":["callback","api-misuse","async"],"backgroundTag":"missing-callback-argument","analyzedSha":"552227599d47ba0493824b7fcf8a00c8cd6404ba","analyzedAt":"2026-09-02T18:40:58.370Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}