{"record":{"id":"a69b0a658580b752","repo":"agalwood/Motrix","slug":"label-must-contain-between-1-and-maxlength-c","errorCode":null,"errorMessage":"${label} must contain between 1 and ${maxLength} characters","messagePattern":"(.+?) must contain between 1 and (.+?) characters","errorType":"validation","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"src/core/inspector-activity/validators.ts","lineNumber":126,"sourceCode":"  assertNonNegativeSafeInteger(delta, 'delta')\n  if (delta > MAX_SAFE_SQLITE_INTEGER - current) {\n    return { value: MAX_SAFE_SQLITE_INTEGER, saturated: true }\n  }\n  return { value: current + delta, saturated: false }\n}\n\nfunction assertBoundedText(\n  value: string | null,\n  label: string,\n  maxLength: number\n): void {\n  if (value === null) return\n  if (\n    typeof value !== 'string' ||\n    value.length === 0 ||\n    value.length > maxLength\n  ) {\n    throw new RangeError(\n      `${label} must contain between 1 and ${maxLength} characters`\n    )\n  }\n}\n\nfunction assertStatus(value: TaskStatus | null, label: string): void {\n  if (value !== null && !STATUS_VALUES.has(value)) {\n    throw new RangeError(`${label} is not a legal task status`)\n  }\n}\n\nfunction assertBoundedDetailParams(\n  value: Record<string, string> | null,\n  label: string,\n  maxJsonLength: number\n): void {\n  if (value === null) return\n  if (","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/agalwood/Motrix/blob/1a708ee57746c434e2c67a44bbf0906a976afea4/src/core/inspector-activity/validators.ts#L108-L144","documentation":"`assertBoundedText` accepts either `null` (treated as absent/ok) or a non-empty string no longer than `maxLength`. It throws this `RangeError` if the value is not a string, is an empty string, or exceeds `maxLength`. The `label` and `maxLength` come from the caller — `eventKey`/`runtimeGeneration` (256), `errorCode` (128), `errorMessage` (2048), `errorDetailKey` (128). The bounds mirror the SQLite TEXT column widths so inserts never truncate.","triggerScenarios":"Submitting a `TaskHistoryEventInput` where a bounded text field is `''` (empty string instead of `null`), an over-long string, or accidentally typed as `undefined`/number. For example, an event with `errorMessage: ''` after a successful retry, or an `errorCode` longer than 128 chars from a verbose engine response.","commonSituations":"Tests using empty strings as placeholders instead of `null`; logging a full stack trace into `errorMessage`; an engine that returns a multi-kilobyte error body; copy-pasting a long URL into `errorDetailKey`.","solutions":["Replace empty strings with `null` for absent fields — the validator explicitly allows null.","Truncate long values before submission: `value.slice(0, maxLength)` (after confirming the loss is acceptable).","Check the field's intended unit — `errorCode` is a short code, `errorMessage` a one-liner; full payloads belong elsewhere.","Wire the producer to the same exported `MAX_*_LENGTH` constants so truncation happens once at the edge."],"exampleFix":"// before\nevent.errorMessage = err.message  // may be '' or 5KB\n// after\nevent.errorMessage = err.message ? err.message.slice(0, 2048) : null","handlingStrategy":"validation","validationCode":"function boundText(value: string | null, max: number): string | null {\n  if (value === null || value.length === 0) return null\n  return value.slice(0, max)\n}","typeGuard":"function isBoundedText(v: unknown, max: number): v is string | null {\n  return v === null || (typeof v === 'string' && v.length > 0 && v.length <= max)\n}","tryCatchPattern":null,"preventionTips":["Treat absent optional strings as `null`, never as an empty string.","Reuse the exported `MAX_*_LENGTH` constants at every producer site.","Add a schema validator (e.g. zod) at the IPC boundary to catch over-long fields before they reach the validator."],"tags":["validation","range-error","strings","inspector-activity"],"backgroundTag":null,"analyzedSha":"1a708ee57746c434e2c67a44bbf0906a976afea4","analyzedAt":"2026-08-12T16:18:09.346Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}