amark/gun · error · Error
Missing Callback
Error message
Missing Callback
What it means
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.
Source
Thrown at lib/ison.js:669
* @return { number }
*/
let validateIntensity = (intensity) => {
intensity = Math.round(intensity);
if (intensity > 0 && intensity <= 32)
return intensity;
else if (intensity <= 0)
return 1;
else
return 32;
};
yson.parseAsync = function (data, callback, reviver = null, intensity = 1) {
//Bring parity with the in-built parser, that takes both string and buffer
if (Buffer.isBuffer(data))
data = data.toString();
if (!callback)
throw new Error('Missing Callback');
intensity = validateIntensity(intensity);
return parseWrapper(data, reviver, intensity, callback);
};
/**
* Error checking and call of appropriate functions for JSON stringify API
* @param { primitive data types } data
* @param { function or array } replacer
* @param { number or string } space
* @param { number } intensity
* @param { function } callback
* @return { function } stringifyWrapper
*/
yson.stringifyAsync = function(data, callback, replacer = null, space, intensity = 1) {
if (typeof callback !== 'function') {
throw new TypeError('Callback is not a function');View on GitHub (pinned to 552227599d)
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
Example fix
// before
const obj = yson.parseAsync(str, null);
// after
yson.parseAsync(str, (err, obj) => {
if (err) return console.error(err);
console.log(obj);
}); Defensive patterns
Strategy: type-guard
Validate before calling
function canParseAsync(data, cb) {
return typeof cb === 'function';
}
if (!canParseAsync(str, myCallback)) throw new Error('parseAsync requires a callback'); Type guard
const isFn = (v) => typeof v === 'function';
if (!isFn(cb)) throw new TypeError('callback must be a function'); Try / catch
try {
yson.parseAsync(data, (err, res) => { if (err) throw err; use(res); });
} catch (e) {
// synchronous throw: missing/invalid callback
console.error('parseAsync setup failed:', e.message);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of amark/gun@552227599d (2026-09-02).
Data as JSON: /api/errors/a8918bfdbd46c9da.
Report an issue: GitHub.