{"record":{"id":"bcc8c0f2ed000090","repo":"amark/gun","slug":"callback-is-not-a-function","errorCode":null,"errorMessage":"Callback is not a function","messagePattern":"Callback is not a function","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/ison.js","lineNumber":687,"sourceCode":"\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');\n  }\n  if (typeof space === 'number' || typeof space === 'string')\n    space = validateSpace(space);\n  if (typeof intensity === 'number')\n    intensity = validateIntensity(intensity);\n  return stringifyWrapper(data, replacer, space, intensity, callback);\n}\n\nif(typeof window != ''+u){ window.YSON = yson }\ntry{ if(typeof module != ''+u){ module.exports = yson } }catch(e){}\nif(typeof JSON != ''+u){\n\tJSON.parseAsync = yson.parseAsync;\n\tJSON.stringifyAsync = yson.stringifyAsync;\n}\n\n}());\n","sourceCodeStart":669,"sourceCodeEnd":704,"githubUrl":"https://github.com/amark/gun/blob/552227599d47ba0493824b7fcf8a00c8cd6404ba/lib/ison.js#L669-L704","documentation":"yson.stringifyAsync serializes data asynchronously and delivers the result via a callback. It validates that the second argument is actually a function and throws a TypeError when it is not — catching cases where a non-callable (string, object, undefined) was passed in the callback position.","triggerScenarios":"Calling yson.stringifyAsync(data) with no callback; passing a non-function (e.g. a replacer string or space value) in the second position due to argument-order confusion with the signature (data, callback, replacer, space, intensity); a variable holding the callback being undefined at call time.","commonSituations":"Refactoring from synchronous JSON.stringify(value, replacer, space) and keeping the old argument order (replacer second) — here replacer must be third; copying stringify code that omitted the callback; typos in the callback variable name.","solutions":["Pass a function as the second argument: yson.stringifyAsync(data, (err, res) => { ... })","Verify argument order: callback is argument 2, replacer argument 3, space argument 4, intensity argument 5","Ensure the callback variable is defined and is a function at the call site","Wrap in a type check in dev: if (typeof cb !== 'function') throw before calling"],"exampleFix":"// before — old JSON.stringify order leaks replacer into callback slot\nyson.stringifyAsync(data, replacer, 2, (err, res) => {});\n// after\nyson.stringifyAsync(data, (err, res) => {\n  if (err) return console.error(err);\n}, replacer, 2);","handlingStrategy":"type-guard","validationCode":"if (typeof callback !== 'function') {\n  throw new TypeError('stringifyAsync requires a function callback');\n}","typeGuard":"const isFn = (v) => typeof v === 'function';\nif (!isFn(cb)) throw new TypeError('callback must be a function');","tryCatchPattern":"try {\n  yson.stringifyAsync(data, (err, res) => { if (err) throw err; }, replacer, space, intensity);\n} catch (e) {\n  console.error('stringifyAsync setup failed:', e.message);\n}","preventionTips":["Keep JSON.stringify argument-order in mind but adapt: callback is 2nd, replacer 3rd","Type-check the callback variable before calling","Centralize serialization in a helper that injects the callback"],"tags":["callback","typeerror","api-misuse"],"backgroundTag":"missing-callback-argument","analyzedSha":"552227599d47ba0493824b7fcf8a00c8cd6404ba","analyzedAt":"2026-09-02T18:40:58.370Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}