pydantic/monty · error · TypeError
Unknown Monty marker type: ${String(object[TYPE_MARKER])}
Error message
Unknown Monty marker type: ${String(object[TYPE_MARKER])} What it means
pushMarked converts Monty's marker-tagged value objects (values carrying a TYPE_MARKER symbol) into flat wire nodes for the wasm worker transport. This TypeError is thrown when the marker string does not match any known marker type in the switch, meaning the object was forged, corrupted, or produced by a mismatched monty version.
Source
Thrown at crates/monty-js/ts/worker/value.ts:149
excType: String(object.excType),
...(typeof object.message === 'string' ? { message: object.message } : {}),
},
}
case 'ClassInstance':
return pushClassInstance(object, nodes)
case 'FileHandle':
return pushFileHandle(object)
case 'Type':
// A class type marker (`classType`) crosses structurally; builtin type
// markers carry only the name.
if (typeof object.classType === 'object' && object.classType !== null) {
return { tag: 'class-type', val: pushClassType(object.classType as Record<string, unknown>, nodes) }
}
return { tag: 'type-name', val: String(object.value) }
case 'BuiltinFunction':
return { tag: 'builtin-function', val: String(object.value) }
default:
throw new TypeError(`Unknown Monty marker type: ${String(object[TYPE_MARKER])}`)
}
}
/** Preserves aware-time metadata while rejecting an orphaned timezone name. */
function timeZoneFields(
object: Record<string, unknown>,
typeName: 'DateTime' | 'Time',
): { offsetSeconds?: number; timezoneName?: string } {
const aware = object.offsetSeconds !== undefined && object.offsetSeconds !== null
if (!aware && object.timezoneName !== undefined && object.timezoneName !== null) {
throw new TypeError(`Monty${typeName} timezoneName requires offsetSeconds`)
}
return aware
? {
offsetSeconds: Number(object.offsetSeconds),
...(typeof object.timezoneName === 'string' ? { timezoneName: object.timezoneName } : {}),
}
: {}View on GitHub (pinned to adc986b362)
Solutions
- Pass only values originally produced by the monty runtime (or documented input shapes), never hand-built marker objects
- Align @pydantic/monty and the monty binary/wasm component to the same released version
- Log String(object[TYPE_MARKER]) to identify the unrecognized marker and check whether it is a newer marker type your wrapper does not know
- If intentionally extending, add the marker to pushMarked's switch
Example fix
// before
const input = { [TYPE_MARKER]: 'CustomThing', value: 1 } // unknown marker
// after
const input = 1 // plain JS value, or a value received from the runtime Defensive patterns
Strategy: type-guard
Validate before calling
function isKnownMarker(v: unknown): boolean {
const KNOWN = new Set(['DateTime','Time','TimeDelta','Date','ClassInstance','ClassType','BuiltinFunction','TypeName','Uuid' /* etc */])
return typeof v === 'object' && v !== null && KNOWN.has(String((v as any)[TYPE_MARKER]))
} Type guard
const isMarked = (v: unknown): v is Record<PropertyKey, unknown> => typeof v === 'object' && v !== null && typeof (v as any)[TYPE_MARKER] === 'string'
Try / catch
try {
const node = pushValue(input, nodes)
} catch (e) {
if (e instanceof TypeError && e.message.startsWith('Unknown Monty marker type')) {
throw new Error(`Unconvertible input value: ${e.message}`)
}
throw e
} Prevention
- Only pass values produced by the runtime or plain JSON-safe values as inputs/return values
- Keep @pydantic/monty, the native binary and wasm component on the same version
- Never construct TYPE_MARKER objects by hand
When it happens
Trigger: Passing a plain or hand-built object with a TYPE_MARKER property whose value is not one of the recognized markers (e.g. 'DateTime', 'ClassInstance', 'BuiltinFunction', etc.) into session inputs or external-function return values; using a @pydantic/monty package version whose marker names differ from the native binary's.
Common situations: Version mismatch between the JS wrapper and the wasm/native runtime after an upgrade; constructing marker objects manually instead of using returned values; deserializing values that were corrupted in transit or by user serialization.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- ClassType attrs entries must be [name, value] pairs
- ClassType attr name must be a string
- ClassType attr value missing
- ${what} must be a canonical uuid string
- MontyFileHandle path must be a string
AI-assisted analysis of pydantic/monty@adc986b362 (2026-09-13).
Data as JSON: /api/errors/fc844592f7a13c5a.
Report an issue: GitHub.