{"record":{"id":"5ff03148c6f8bd27","repo":"koala73/worldmonitor","slug":"enter-an-operation-name-of-1-100-characters","errorCode":null,"errorMessage":"Enter an operation name of 1-100 characters.","messagePattern":"Enter an operation name of 1-100 characters\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utils/operational-balance.ts","lineNumber":30,"sourceCode":"  return value as Record<string, unknown>;\n}\nfunction quantity(value: unknown, label: string): number {\n  if (value === '' || value === null || value === undefined) throw new Error(`${label} is required.`);\n  if (typeof value !== 'number' || !Number.isFinite(value) || value < 0 || value > 1e6 || round(value) !== value) {\n    throw new Error(`${label} must be between 0 and 1 million with at most 6 decimal places.`);\n  }\n  return value;\n}\nfunction date(value: unknown): string {\n  if (typeof value !== 'string' || !/^\\d{4}-\\d{2}-\\d{2}$/.test(value) || !Number.isFinite(Date.parse(value)) || new Date(value).toISOString().slice(0, 10) !== value || value < '1900-01-01' || value > '9998-12-31') {\n    throw new Error('Use a valid date from 1900 through 9998.');\n  }\n  return value;\n}\n\nexport function parseOperationalInput(value: unknown): OperationalInput {\n  const input = record(value);\n  if (typeof input.operation !== 'string' || !input.operation.trim() || input.operation.length > 100) throw new Error('Enter an operation name of 1-100 characters.');\n  if (typeof input.unit !== 'string' || !/^[\\p{L}\\p{N} %./-]{1,24}$/u.test(input.unit) || !input.unit.trim()) throw new Error('Enter one quantity unit of 1-24 characters.');\n  const unit = input.unit.trim();\n  const startDate = date(input.startDate);\n  if (!Number.isInteger(input.horizonDays) || (input.horizonDays as number) < 1 || (input.horizonDays as number) > MAX_OPERATIONAL_DAYS) throw new Error('Horizon must be 1-90 whole days.');\n  const horizonDays = input.horizonDays as number;\n  if (input.basis !== 'example' && input.basis !== 'user') throw new Error('Input basis must be example or user.');\n  const deliveries = (value: unknown): OperationalDelivery[] => {\n    if (!Array.isArray(value) || value.length > MAX_OPERATIONAL_DELIVERIES) throw new Error('Use at most 30 deliveries per list.');\n    return value.map(value => {\n      const row = record(value);\n      const deliveryDate = date(row.date);\n      if (deliveryDate < startDate || deliveryDate > dateAt(startDate, horizonDays - 1)) throw new Error('Delivery dates must be inside the selected horizon.');\n      if (row.unit !== unit) throw new Error(`Every delivery must use ${unit}; mixed units are not converted.`);\n      return { date: deliveryDate, unit, quantity: quantity(row.quantity, 'Delivery quantity'), costUsd: row.costUsd === null || row.costUsd === undefined ? null : quantity(row.costUsd, 'Delivery cost') };\n    });\n  };\n  return { operation: input.operation.trim(), basis: input.basis, unit, startDate, horizonDays,\n    startingStock: quantity(input.startingStock, 'Starting stock'), dailyDemand: quantity(input.dailyDemand, 'Daily demand'),","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/koala73/worldmonitor/blob/7d06c8633d256c18e38133030bc3613976a96ec9/src/utils/operational-balance.ts#L12-L48","documentation":"parseOperationalInput validates the operation name as a non-empty trimmed string of at most 100 characters; whitespace-only names are rejected via input.operation.trim(). It throws 'Enter an operation name of 1-100 characters.' when the field is missing, not a string, blank, or longer than 100 characters.","triggerScenarios":"Omitting the operation field, sending null/undefined or a number, submitting a form with only spaces, or pasting a description longer than 100 characters into the operation field.","commonSituations":"Form autosave persisting an empty name; API consumers using a different field name (e.g. title or name) so operation is undefined; copy-pasted long operation descriptions from planning documents.","solutions":["Provide a non-empty operation string, trimmed, at most 100 characters.","Trim and check length in the form before submission: op.trim().length >= 1 && op.length <= 100.","Map alternate field names (title/name) to operation at the API boundary."],"exampleFix":"// before\nparseOperationalInput({ operation: '   ', ... });\n// after\nparseOperationalInput({ operation: 'Operation Desert Resupply'.slice(0, 100), ... });","handlingStrategy":"validation","validationCode":"const op = (payload as any)?.operation;\nif (typeof op !== 'string' || !op.trim() || op.length > 100) {\n  throw new Error('Operation name must be 1-100 non-blank characters');\n}","typeGuard":"const hasValidOperation = (w: unknown): w is { operation: string } & Record<string, unknown> =>\n  w !== null && typeof w === 'object' && typeof (w as any).operation === 'string' &&\n  (w as any).operation.trim().length > 0 && (w as any).operation.length <= 100;","tryCatchPattern":"try {\n  const input = parseOperationalInput(raw);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('operation name of 1-100')) {\n    console.error('Operation name missing, blank, or over 100 chars:', e.message);\n  } else throw e;\n}","preventionTips":["Make the operation field required and non-blank in the form.","Trim and length-check on input events, not only at submit.","Map alternate field names (title/name) to operation at the boundary.","Set maxlength=\"100\" on the operation input."],"tags":["validation","required-field","length-limit"],"backgroundTag":"empty-required-field","analyzedSha":"7d06c8633d256c18e38133030bc3613976a96ec9","analyzedAt":"2026-09-15T16:44:39.439Z","contentChangedAt":"2026-09-15T16:44:39.439Z","schemaVersion":2},"datasetVersion":"2026-09-15T18:17:12.389Z"}