{"record":{"id":"734a6d43952b761a","repo":"pydantic/monty","slug":"value-of-type-typeof-value","errorCode":null,"errorMessage":"value of type ${typeof value}","messagePattern":"value of type (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/monty-js/ts/worker/value.ts","lineNumber":65,"sourceCode":"  } else if (value instanceof Uint8Array) {\n    node = { tag: 'bytes', val: value }\n  } else if (Array.isArray(value)) {\n    const items = Uint32Array.from(value.map((item) => pushValue(item, nodes)))\n    node = { tag: isTuple(value) ? 'tuple-value' : 'list-value', val: items }\n  } else if (value instanceof Map) {\n    node = { tag: 'dict', val: pushPairs([...value.entries()], nodes) }\n  } else if (value instanceof Set) {\n    node = { tag: 'set', val: Uint32Array.from([...value].map((item) => pushValue(item, nodes))) }\n  } else if (typeof value === 'function') {\n    node = { tag: 'function', val: { name: value.name ?? '' } }\n  } else if (typeof value === 'object') {\n    const object = value as Record<string, unknown>\n    node =\n      TYPE_MARKER in object ? pushMarked(object, nodes) : { tag: 'dict', val: pushPairs(Object.entries(object), nodes) }\n  } else if (typeof value === 'symbol') {\n    throw new TypeError('Cannot convert JS Symbol to Monty value')\n  } else {\n    throw unsupported(`value of type ${typeof value}`)\n  }\n  const index = nodes.length\n  nodes.push(node)\n  return index\n}\n\n/** Converts a `__monty_type__` marker into one semantic value node. */\nfunction pushMarked(object: Record<string, unknown>, nodes: ValueNode[]): ValueNode {\n  switch (object[TYPE_MARKER]) {\n    case 'Ellipsis':\n      return { tag: 'ellipsis' }\n    case 'NotImplemented':\n      return { tag: 'not-implemented' }\n    case 'Date':\n      return {\n        tag: 'date',\n        val: { year: Number(object.year), month: Number(object.month), day: Number(object.day) },\n      }","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-js/ts/worker/value.ts#L47-L83","documentation":"In the wasm worker path of `@pydantic/monty` (`crates/monty-js/ts/worker/value.ts:65`, in `pushValue`, used by `encodeValue` when marshaling inputs/results across the component boundary), a JavaScript value could not be mapped to any Monty value node. After all known `typeof` kinds are handled (and `symbol` throws its own TypeError), the final fallback throws this `unsupported` error naming the unresolved `typeof` — practically a defensive branch for values JS surfaces outside the enumerated set.","triggerScenarios":"Passing a value into `session.feedRun` inputs, a return value from an `externalLookup` function, or any host callback result that `encodeValue` cannot classify: not null/boolean/number/bigint/string/Uint8Array/Array/Map/Set/function/plain-object/marked object, and not a `symbol` (which gets its own TypeError). In practice this fires only for exotic `typeof` results outside ECMAScript's standard set (e.g. non-standard host/undocumented typeof values or a future JS typeof kind).","commonSituations":"Rare; usually seen when a custom class instance with an exotic proxy/undici-style wrapper or a host-provided exotic object flows into the drive loop, or when a JS engine/embedding reports a non-standard `typeof`. Standard JS values convert fine — plain objects become dicts, Maps/Sets/typed data all have dedicated branches.","solutions":["Log `typeof value` (and `Object.prototype.toString.call(value)`) on the offending input and convert it to a supported type before calling the session API.","Wrap exotic objects in plain objects, arrays, strings, numbers, bigints, Maps, Sets, or `Uint8Array` — the types `pushValue` understands.","Use the documented `__monty_type__` marker helpers for special Monty values (Ellipsis, Date, etc.) instead of host wrapper objects.","If this fires for a standard JS value, report a bug: the fallback is expected to be unreachable for standard ECMAScript types."],"exampleFix":"// before\nawait session.feedRun(code, { inputs: { handle: someExoticHostObject } });\n\n// after\nawait session.feedRun(code, {\n  inputs: { handle: { id: someExoticHostObject.id, kind: String(someExoticHostObject.kind) } },\n});","handlingStrategy":"type-guard","validationCode":"// Ensure values crossing the Monty boundary are convertible\nfunction isMontySafe(value: unknown): boolean {\n  return (\n    value === null || value === undefined ||\n    ['boolean', 'number', 'bigint', 'string', 'function'].includes(typeof value) ||\n    value instanceof Uint8Array || value instanceof Map || value instanceof Set ||\n    Array.isArray(value) || (typeof value === 'object')\n  );\n}\n// Pre-check inputs: Object.values(inputs).every(isMontySafe)","typeGuard":"function isConvertibleToMonty(value: unknown): value is\n  null | undefined | boolean | number | bigint | string | Uint8Array | Map<unknown, unknown> | Set<unknown> | unknown[] | Record<string, unknown> | Function {\n  return value === null || value === undefined || typeof value !== 'symbol';\n}","tryCatchPattern":"import { MontyError } from '@pydantic/monty';\ntry {\n  await session.feedRun(code, { inputs });\n} catch (err) {\n  if (err instanceof MontyError && String(err.message).startsWith('unsupported: value of type')) {\n    console.error('Unconvertible input:', Object.values(inputs).map(v => typeof v));\n  }\n  throw err;\n}","preventionTips":["Only pass plain JS data (objects, arrays, strings, numbers, bigints, Maps, Sets, Uint8Array) into Monty sessions and callbacks.","Never pass Symbols; the converter rejects them explicitly — use strings as keys/names instead.","Unwrap host wrapper objects (proxies, class instances with exotic behavior) into plain objects before crossing the boundary.","Type inputs with the exported session input types so exotic values are caught at compile time."],"tags":["typescript","wasm","value-conversion","unsupported-type","javascript"],"backgroundTag":"incompatible-source-type","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}