agalwood/Motrix · error · RangeError

taskId must contain between 1 and ${MAX_TASK_ID_LENGTH} char

Error message

taskId must contain between 1 and ${MAX_TASK_ID_LENGTH} characters

What it means

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.

Source

Thrown at src/core/inspector-activity/validators.ts:37

export const MAX_SAMPLE_FLAGS = 2_147_483_647

const STATUS_VALUES = new Set<string>(Object.values(TaskStatus))
const EVENT_KIND_VALUES = new Set<string>(Object.values(TaskHistoryEventKind))
const ACCURACY_VALUES = new Set<string>(Object.values(TaskHistoryAccuracy))
const DELIVERY_VALUES = new Set<string>(Object.values(TaskHistoryDelivery))
const ACTIVE_RESUME_STATUSES = new Set<TaskStatus>([
  TaskStatus.FetchingMetadata,
  TaskStatus.Downloading,
  TaskStatus.Finalizing,
  TaskStatus.Seeding,
])

export function assertTaskId(taskId: string): string {
  if (typeof taskId !== 'string') {
    throw new RangeError('taskId must be a string')
  }
  if (taskId.length > MAX_TASK_ID_LENGTH) {
    throw new RangeError(
      `taskId must contain between 1 and ${MAX_TASK_ID_LENGTH} characters`
    )
  }
  const normalized = taskId.trim()
  if (normalized.length === 0 || normalized.length > MAX_TASK_ID_LENGTH) {
    throw new RangeError(
      `taskId must contain between 1 and ${MAX_TASK_ID_LENGTH} characters`
    )
  }
  return normalized
}

export function assertPositiveSafeInteger(
  value: number,
  label: string
): number {
  if (!Number.isSafeInteger(value) || value <= 0) {
    throw new RangeError(`${label} must be a positive safe integer`)

View on GitHub (pinned to 1a708ee577)

Solutions

  1. Shorten or regenerate the taskId to fit within MAX_TASK_ID_LENGTH.
  2. Trim whitespace and noise from the id before validation.
  3. Validate length at the producer so oversized ids never reach the validator.

Example fix

// before
assertTaskId(veryLongId) // length > MAX_TASK_ID_LENGTH -> RangeError

// after
const trimmed = veryLongId.trim().slice(0, MAX_TASK_ID_LENGTH)
assertTaskId(trimmed)
Defensive patterns

Strategy: validation

Validate before calling

// Cap and trim before validating.
const candidate = String(raw).trim().slice(0, MAX_TASK_ID_LENGTH)
assertTaskId(candidate)

Type guard

function fitsTaskIdLength(s: string): boolean {
  return s.length > 0 && s.length <= MAX_TASK_ID_LENGTH
}

Try / catch

try {
  assertTaskId(id)
} catch (err) {
  if (err instanceof RangeError && /between 1 and/.test(err.message)) {
    // regenerate or truncate the id
  } else throw err
}

Prevention

When it happens

Trigger: taskId.length > MAX_TASK_ID_LENGTH on the raw input string, before any trimming.

Common situations: 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.

Related errors


AI-assisted analysis of agalwood/Motrix@1a708ee577 (2026-08-12). Data as JSON: /api/errors/fa6a897cc9e3929e. Report an issue: GitHub.