stringifyValueForError crashes on function-valued args, masking the real error
Bug
In npm-packages/convex (convex npm package), stringifyValueForError in src/browser/values/value.ts crashes when the value passed to JSON.stringify is a bare function (or the top-level value serializes to undefined):
```ts export function stringifyValueForError(value: any) { const str = JSON.stringify(value, (_key, value) => { if (value === undefined) { return "undefined"; } if (typeof value === "bigint") { return `${value.toString()}n`; } return value; }); if (str.length > MAX_VALUE_FOR_ERROR_LEN) { // str === undefined → TypeError ```
When an action/mutation arg contains a function (e.g. a library object decorated with methods), convexToJson correctly identifies it as an unsupported type and calls errorMessageForUnsupportedType → stringifyValueForError(value). But JSON.stringify(fn) returns undefined, so str.length throws `TypeError: Cannot read properties of undefined (reading 'length')` — masking the real "not a supported Convex type" error and making the underlying problem undebuggable.
Repro
```ts import { convexToJson } from "convex/values"; convexToJson({ cb: () => {} }); // expected: Error "...is not a supported Convex type..." // actual: TypeError: Cannot read properties of undefined (reading 'length') ```
The nested case also crashes when the whole unsupported value is a function: `convexToJson(() => {})` hits the same path via `errorMessageForUnsupportedType` → `stringifyValueForError(fn)`.
Fix sketch
Guard the undefined case:
```ts const str = JSON.stringify(value, replacer) ?? String(value); ```
or return a placeholder for non-serializable top-level values (functions, symbols) in the replacer, the same way `undefined` is handled.
Observed on convex 1.46.x. Found while integrating a React Native passkeys library that decorates attestation objects with methods (`getPublicKey()`) — the function-valued arg case is a realistic shape from third-party libs.
Source: get-convex/convex-backend