{"record":{"id":"6b7b6ac8d7461a7a","repo":"sickn33/agentic-awesome-skills","slug":"invalid-age","errorCode":null,"errorMessage":"Invalid age","messagePattern":"Invalid age","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"skills/fp-pragmatic/SKILL.md","lineNumber":113,"sourceCode":"```\n\n**Plain language translation:**\n- `O.fromNullable(x)` = \"wrap this value, treating null/undefined as 'nothing'\"\n- `O.flatMap(fn)` = \"if we have something, apply this function\"\n- `O.getOrElse(() => default)` = \"unwrap, or use this default if nothing\"\n\n### 3. Either: Make Errors Explicit\n\nStop throwing exceptions for expected failures. Return errors as values.\n\n```typescript\nimport * as E from 'fp-ts/Either'\nimport { pipe } from 'fp-ts/function'\n\n// Before: Hidden failure mode\nfunction parseAge(input: string): number {\n  const age = parseInt(input, 10)\n  if (isNaN(age)) throw new Error('Invalid age')\n  if (age < 0) throw new Error('Age cannot be negative')\n  return age\n}\n\n// After: Errors are visible in the type\nfunction parseAge(input: string): E.Either<string, number> {\n  const age = parseInt(input, 10)\n  if (isNaN(age)) return E.left('Invalid age')\n  if (age < 0) return E.left('Age cannot be negative')\n  return E.right(age)\n}\n\n// Using it\nconst result = parseAge(userInput)\nif (E.isRight(result)) {\n  console.log(`Age is ${result.right}`)\n} else {\n  console.log(`Error: ${result.left}`)","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/sickn33/agentic-awesome-skills/blob/58d857988fcfac6986206bca2b2fe223aa437e4b/skills/fp-pragmatic/SKILL.md#L95-L131","documentation":"Thrown by the Before imperative parseAge example in the fp-pragmatic skill (skills/fp-pragmatic/SKILL.md:113) when parseInt(input, 10) yields NaN, i.e. the input is not parseable as an integer. The doc contrasts it with an Either<string, number> return type that surfaces the failure in the signature.","triggerScenarios":"Calling parseAge with an empty string, alphabetic garbage like abc, leading non-numeric text, a nullish value coerced to string, or whitespace-only input.","commonSituations":"Unvalidated form fields or query params passed straight to parsing; locale differences (commas as decimal separators); ages arriving as free text from third-party APIs.","solutions":["Validate and trim input before parsing (reject empty and non-numeric strings at the boundary)","Adopt the doc AFTER version: return E.Either<string, number> and let callers handle Left","Use a schema library (zod/io-ts) to parse and validate in one step"],"exampleFix":"// before\nfunction parseAge(input: string): number {\n  const age = parseInt(input, 10)\n  if (isNaN(age)) throw new Error('Invalid age')\n  return age\n}\n\n// after\nfunction parseAge(input: string): E.Either<string, number> {\n  const age = parseInt(input, 10)\n  return isNaN(age) ? E.left('Invalid age') : E.right(age)\n}","handlingStrategy":"validation","validationCode":"const trimmed = input.trim()\nif (!/^-?[0-9]+$/.test(trimmed)) {\n  return badRequest('age must be an integer')\n}","typeGuard":"const isParsableInt = (s: string): boolean => /^-?[0-9]+$/.test(s.trim())","tryCatchPattern":null,"preventionTips":["Trim and reject empty input before parseInt","Prefer Either-returning parsers or zod coercion","Validate form fields client-side before submission"],"tags":["parsing","validation","nan","documentation-example"],"backgroundTag":"input-parse-failure","analyzedSha":"58d857988fcfac6986206bca2b2fe223aa437e4b","analyzedAt":"2026-08-26T11:55:59.350Z","schemaVersion":2},"datasetVersion":"2026-08-26T14:46:13.012Z"}