gchq/CyberChef · error · OperationError
Encountered a non-implemented type: ${typeof object}
Error message
Encountered a non-implemented type: ${typeof object} What it means
The top-level serialize() function handles null, primitives (via serializeBasicTypes), Arrays, and plain Objects. This 'should be unreachable' throw fires for any value that is not null, not a primitive, not an Array, and not a plain Object — e.g., a Symbol-wrapped object, a Map, a Set, or a class instance that is not caught by instanceof Object.
Source
Thrown at src/core/operations/PHPSerialize.mjs:119
return `a:${object.length}:{${serializedElements.join("")}}`;
} else if (object instanceof Object) {
/**
* Objects
* Note: the output cannot be guaranteed to be in the same order as the input
*/
const serializedElements = [];
const keys = Object.keys(object);
for (const key of keys) {
serializedElements.push(`${serialize(key)}${serialize(object[key])}`);
}
return `a:${keys.length}:{${serializedElements.join("")}}`;
}
/** This should be unreachable */
throw new OperationError(`Encountered a non-implemented type: ${typeof object}`);
}
return serialize(input);
}
}
export default PHPSerialize;
View on GitHub (pinned to 4290ea7539)
Solutions
- Ensure the input is plain JSON-compatible data: only null, booleans, numbers, strings, arrays, and plain objects
- Convert Map/Set instances to plain objects or arrays before serializing
- Run JSON.parse(JSON.stringify(data)) to strip non-standard types before calling the operation
Example fix
// before
const data = { items: new Map([['a', 1]]) };
// after
const data = { items: Object.fromEntries(new Map([['a', 1]])) }; Defensive patterns
Strategy: type-guard
Validate before calling
// Pre-check: deep-validate that all values are JSON-safe
function isJsonSafe(v) {
if (v === null) return true;
const t = typeof v;
if (t === 'boolean' || t === 'number' || t === 'string') return true;
if (t !== 'object') return false;
if (Array.isArray(v)) return v.every(isJsonSafe);
if (Object.getPrototypeOf(v) !== Object.prototype) return false;
return Object.values(v).every(isJsonSafe);
} Type guard
function isPlainObject(v) {
return v !== null && typeof v === 'object' &&
(Object.getPrototypeOf(v) === Object.prototype || Object.getPrototypeOf(v) === null);
} Try / catch
try {
const result = chef.phpSerialize(input);
} catch (e) {
if (/non-implemented type/i.test(e.message)) {
console.error("Unsupported object type — sanitize input to plain JSON types");
} else { throw e; }
} Prevention
- Convert Map/Set instances to plain objects or arrays before input
- Strip functions and Symbols from the data structure
- Run JSON.parse(JSON.stringify(data)) to normalize to JSON-safe types
When it happens
Trigger: Input JSON contains values whose typeof is 'object' but that are not instances of Object or Array — e.g., a Map, Set, or a non-standard object created with Object.create(null). A Symbol or function value whose typeof is neither 'object' nor a handled primitive type.
Common situations: JSON.parse with a reviver that returns Map or Set instances. Programmatic invocation with data structures containing Symbol or function values. Data mutated after parsing to include non-JSON types.
Related errors
- Encountered a non-implemented type: ${typeof content}
- ${err.toString()}
- ${err.toString()}
- Unable to stringify YAML: ${err}
- End of input reached before end of script
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/fa893a41d4625eaa.
Report an issue: GitHub.