{"record":{"id":"fa6a897cc9e3929e","repo":"agalwood/Motrix","slug":"taskid-must-contain-between-1-and-max-task-id-le","errorCode":null,"errorMessage":"taskId must contain between 1 and ${MAX_TASK_ID_LENGTH} characters","messagePattern":"taskId must contain between 1 and (.+?) characters","errorType":"validation","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"src/core/inspector-activity/validators.ts","lineNumber":37,"sourceCode":"export const MAX_SAMPLE_FLAGS = 2_147_483_647\n\nconst STATUS_VALUES = new Set<string>(Object.values(TaskStatus))\nconst EVENT_KIND_VALUES = new Set<string>(Object.values(TaskHistoryEventKind))\nconst ACCURACY_VALUES = new Set<string>(Object.values(TaskHistoryAccuracy))\nconst DELIVERY_VALUES = new Set<string>(Object.values(TaskHistoryDelivery))\nconst ACTIVE_RESUME_STATUSES = new Set<TaskStatus>([\n  TaskStatus.FetchingMetadata,\n  TaskStatus.Downloading,\n  TaskStatus.Finalizing,\n  TaskStatus.Seeding,\n])\n\nexport function assertTaskId(taskId: string): string {\n  if (typeof taskId !== 'string') {\n    throw new RangeError('taskId must be a string')\n  }\n  if (taskId.length > MAX_TASK_ID_LENGTH) {\n    throw new RangeError(\n      `taskId must contain between 1 and ${MAX_TASK_ID_LENGTH} characters`\n    )\n  }\n  const normalized = taskId.trim()\n  if (normalized.length === 0 || normalized.length > MAX_TASK_ID_LENGTH) {\n    throw new RangeError(\n      `taskId must contain between 1 and ${MAX_TASK_ID_LENGTH} characters`\n    )\n  }\n  return normalized\n}\n\nexport function assertPositiveSafeInteger(\n  value: number,\n  label: string\n): number {\n  if (!Number.isSafeInteger(value) || value <= 0) {\n    throw new RangeError(`${label} must be a positive safe integer`)","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/agalwood/Motrix/blob/1a708ee57746c434e2c67a44bbf0906a976afea4/src/core/inspector-activity/validators.ts#L19-L55","documentation":"RangeError from assertTaskId when the raw (pre-trim) taskId string length exceeds MAX_TASK_ID_LENGTH. This first length check rejects oversized ids before normalization; a later check (error 35) re-validates the trimmed form.","triggerScenarios":"taskId.length > MAX_TASK_ID_LENGTH on the raw input string, before any trimming.","commonSituations":"A copy/paste id with trailing garbage; a generated/UUID id longer than the cap; a malformed payload with a hugely long string; an off-by-one in id generation exceeding the cap.","solutions":["Shorten or regenerate the taskId to fit within MAX_TASK_ID_LENGTH.","Trim whitespace and noise from the id before validation.","Validate length at the producer so oversized ids never reach the validator."],"exampleFix":"// before\nassertTaskId(veryLongId) // length > MAX_TASK_ID_LENGTH -> RangeError\n\n// after\nconst trimmed = veryLongId.trim().slice(0, MAX_TASK_ID_LENGTH)\nassertTaskId(trimmed)","handlingStrategy":"validation","validationCode":"// Cap and trim before validating.\nconst candidate = String(raw).trim().slice(0, MAX_TASK_ID_LENGTH)\nassertTaskId(candidate)","typeGuard":"function fitsTaskIdLength(s: string): boolean {\n  return s.length > 0 && s.length <= MAX_TASK_ID_LENGTH\n}","tryCatchPattern":"try {\n  assertTaskId(id)\n} catch (err) {\n  if (err instanceof RangeError && /between 1 and/.test(err.message)) {\n    // regenerate or truncate the id\n  } else throw err\n}","preventionTips":["Generate taskIds with a fixed-length scheme (e.g. UUID/truncated hash).","Trim and cap ids at the producer.","Validate length client-side before IPC."],"tags":["validation","task","range-error","length"],"backgroundTag":null,"analyzedSha":"1a708ee57746c434e2c67a44bbf0906a976afea4","analyzedAt":"2026-08-12T16:18:09.346Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}