{"record":{"id":"ae47cd1eedfac33d","repo":"sickn33/agentic-awesome-skills","slug":"age-must-be-a-number","errorCode":null,"errorMessage":"Age must be a number","messagePattern":"Age must be a number","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"skills/fp-refactor/SKILL.md","lineNumber":76,"sourceCode":"function parseJSON(input: string): unknown {\n  try {\n    return JSON.parse(input);\n  } catch (error) {\n    throw new Error(`Invalid JSON: ${error}`);\n  }\n}\n\nfunction validateUser(data: unknown): User {\n  try {\n    if (!data || typeof data !== 'object') {\n      throw new Error('Data must be an object');\n    }\n    const obj = data as Record<string, unknown>;\n    if (typeof obj.name !== 'string') {\n      throw new Error('Name is required');\n    }\n    if (typeof obj.age !== 'number') {\n      throw new Error('Age must be a number');\n    }\n    return { name: obj.name, age: obj.age };\n  } catch (error) {\n    throw error;\n  }\n}\n\n// Usage with nested try-catch\nfunction processUserInput(input: string): User | null {\n  try {\n    const data = parseJSON(input);\n    const user = validateUser(data);\n    return user;\n  } catch (error) {\n    console.error('Failed to process user:', error);\n    return null;\n  }\n}","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/sickn33/agentic-awesome-skills/blob/58d857988fcfac6986206bca2b2fe223aa437e4b/skills/fp-refactor/SKILL.md#L58-L94","documentation":"Second field guard in fp-refactor's validateUser: the object passed the name check but `age` is missing or not a number. The surrounding code even wraps the throws in a redundant try/catch that rethrows — itself a refactor target in the skill.","triggerScenarios":"validateUser({ name: 'Bob' }) with age omitted, or age as '30', null, or boolean.","commonSituations":"HTML form values arriving as strings; CSV/Excel imports with blank cells; JSON from loose backends that allow age: null.","solutions":["Parse and coerce age at the edge (Number(), parseInt with NaN check) when the source is textual","Declare age as required number in a shared schema and validate payloads before they reach business code","Return the error as a value with Either instead of throwing"],"exampleFix":"// before\nif (typeof obj.age !== 'number') throw new Error('Age must be a number')\n\n// after\nconst parseAge = (v: unknown): E.Either<string, number> =>\n  typeof v === 'number' && Number.isFinite(v) ? E.right(v) : E.left('Age must be a number')","handlingStrategy":"validation","validationCode":"const toNumber = (v: unknown): number | null => {\n  const n = typeof v === 'number' ? v : Number(v)\n  return Number.isFinite(n) ? n : null\n}","typeGuard":"const hasNumberAge = (x: unknown): x is { age: number } =>\n  typeof x === 'object' && x !== null && typeof (x as any).age === 'number'","tryCatchPattern":null,"preventionTips":["Coerce string form values before validation","Mark numeric fields as required in boundary schemas"],"tags":["validation","runtime-type-check","typescript"],"backgroundTag":"schema-validation-failed","analyzedSha":"58d857988fcfac6986206bca2b2fe223aa437e4b","analyzedAt":"2026-08-26T11:55:59.350Z","schemaVersion":2},"datasetVersion":"2026-08-26T14:46:13.012Z"}