antonmedv/fx · error · Error
Cannot save undefined
Error message
Cannot save undefined
What it means
Guard inside the save() stdlib helper: it rejects calls with an argument that is undefined before serializing, since JSON.stringify would otherwise silently coerce undefined to nothing. Fires when script code calls save() with no argument or with an expression evaluating to undefined, e.g. a missing object property.
Source
Thrown at internal/engine/stdlib.js:188
const copy = [...x]
copy.splice(key, 1)
return copy
}
if (typeof x === 'object' && x !== null) {
const copy = {...x}
delete copy[key]
return copy
}
throw new Error(`Cannot delete key from ${typeof x}`)
}
}
function exit(code) {
__exit__(code)
}
function save(x) {
if (typeof x === 'undefined') throw new Error('Cannot save undefined')
__save__(__stringify__(x, null, 2))
return x
}
function toBase64(x) {
return __toBase64__(x)
}
function fromBase64(x) {
return __fromBase64__(x)
}
const YAML = {
stringify: x => __yaml_stringify__(x),
parse: x => JSON.parse(__yaml_parse__(x)),
}
View on GitHub (pinned to 4f31cd3a0c)
Solutions
- Pass a defined value to save(), e.g. save(.) or save(result)
- Check the variable before saving: if (typeof x !== 'undefined') save(x)
- Use save(null) or save({}) if an explicit empty value is intended
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/engine/stdlib.js:188 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of antonmedv/fx@4f31cd3a0c (2026-09-02).
Data as JSON: /api/errors/cd654849fba24074.
Report an issue: GitHub.