{"record":{"id":"2f51d5256f02313c","repo":"pydantic/monty","slug":"assertmessageannotations-must-be-a-boolean-or-an-integer","errorCode":null,"errorMessage":"assertMessageAnnotations must be a boolean or an integer between 1 and 2**32 - 1","messagePattern":"assertMessageAnnotations must be a boolean or an integer between 1 and 2\\*\\*32 - 1","errorType":"validation","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"crates/monty-js/ts/options.ts","lineNumber":71,"sourceCode":"/**\n * The `assertMessageAnnotations` checkout option: `true`/`false`, or an\n * integer customizing the per-operand repr truncation length (in bytes,\n * default 120) of introspected `assert` failure messages.\n */\nexport type AssertMessageAnnotations = boolean | number\n\n/**\n * Normalizes {@link AssertMessageAnnotations} to the wire encoding of\n * `Configure.assert_message_annotations`: `undefined`/`true` → absent (the\n * child's default, a 120-byte truncation), `false` → `0` (off), an integer →\n * a custom truncation length. Throws `RangeError` for numbers the wire's\n * uint32 cannot carry (non-integers, `< 1`, `> 2**32 - 1`).\n */\nexport function encodeAssertMessageAnnotations(value: AssertMessageAnnotations | undefined): number | undefined {\n  if (value === undefined || value === true) return undefined\n  if (value === false) return 0\n  if (!Number.isInteger(value) || value < 1 || value > 0xffff_ffff) {\n    throw new RangeError('assertMessageAnnotations must be a boolean or an integer between 1 and 2**32 - 1')\n  }\n  return value\n}\n","sourceCodeStart":53,"sourceCodeEnd":75,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-js/ts/options.ts#L53-L75","documentation":"`assertMessageAnnotations` controls how many annotated asserts are kept and must be `true`, `false`, or a positive 32-bit integer. Values that are non-integers, `< 1`, or exceed `2**32 - 1` cannot be encoded as a uint32 on the wire, so a `RangeError` is thrown up front.","triggerScenarios":"`pool.checkout({ assertMessageAnnotations: 0 })`, a float like `1.5`, a huge number like `2**40`, or a string `'true'` instead of a boolean.","commonSituations":"Config value parsed from JSON/env ending up as a string or float; intent to 'unlimited' encoded as 0 or a sentinel like `Infinity` or `-1`.","solutions":["Use `true` to keep all annotated asserts, `false`/`0` to disable, or an integer >= 1 and <= 4294967295","Clamp and floor numeric config: `Math.min(Math.max(Math.floor(v), 1), 0xffff_ffff)`","Replace sentinel 'unlimited' values with `true`"],"exampleFix":"// before\nconst session = await pool.checkout({ assertMessageAnnotations: -1 }) // unlimited?\n// after\nconst session = await pool.checkout({ assertMessageAnnotations: true }) // or an integer like 1000","handlingStrategy":"validation","validationCode":"const v = opts.assertMessageAnnotations\nif (!(v === undefined || typeof v === 'boolean' || (Number.isInteger(v) && v >= 1 && v <= 0xffff_ffff))) {\n  throw new Error(`invalid assertMessageAnnotations: ${v}`)\n}","typeGuard":"function isValidAssertAnnotations(v: unknown): boolean {\n  return v === undefined || typeof v === 'boolean' ||\n    (typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 0xffff_ffff)\n}","tryCatchPattern":"try {\n  session = await pool.checkout(opts)\n} catch (e) {\n  if (e instanceof RangeError && e.message.includes('assertMessageAnnotations')) {\n    delete opts.assertMessageAnnotations // use default\n    session = await pool.checkout(opts)\n  } else throw e\n}","preventionTips":["Use `true`/`false` for on/off; only use integers for a bounded count","Floor and clamp numeric config: `Math.min(Math.max(Math.trunc(v), 1), 0xffff_ffff)`","Parse config with `Number()` and reject NaN before passing it in"],"tags":["typescript","options-validation","range"],"backgroundTag":"value-out-of-range","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}