{"record":{"id":"c339f64849c5756c","repo":"sickn33/agentic-awesome-skills","slug":"name-is-required","errorCode":null,"errorMessage":"Name is required","messagePattern":"Name is required","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"skills/fp-refactor/SKILL.md","lineNumber":73,"sourceCode":"#### Before (Imperative)\n\n```typescript\nfunction 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);","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/sickn33/agentic-awesome-skills/blob/58d857988fcfac6986206bca2b2fe223aa437e4b/skills/fp-refactor/SKILL.md#L55-L91","documentation":"The field-level guard in fp-refactor's validateUser: the input is an object but `name` is absent or not a string. Like its siblings, it demonstrates field-by-field throws the skill later replaces.","triggerScenarios":"validateUser({ age: 30 }), validateUser({ name: 123 }), or payloads where name was serialized under a different key (Name, fullName).","commonSituations":"API contract renames; optional fields omitted by clients; numbers auto-coerced by CSV import; localization forms using different field names.","solutions":["Align the field name with the producer's contract (check OpenAPI/schema)","Normalize input keys before validation","Move the check into a schema (zod object({ name: z.string() })) at the boundary"],"exampleFix":"// before\nif (typeof obj.name !== 'string') throw new Error('Name is required')\n\n// after\nconst nameOk = isRecord(data) && typeof data.name === 'string' && data.name.length > 0\nreturn nameOk ? E.right(data as User) : E.left('Name is required')","handlingStrategy":"type-guard","validationCode":"const hasName = (x: unknown) => isRecord(x) && typeof x.name === 'string' && x.name.length > 0","typeGuard":"const hasName = (x: unknown): x is { name: string } =>\n  typeof x === 'object' && x !== null && typeof (x as any).name === 'string'","tryCatchPattern":null,"preventionTips":["Keep field names locked to a shared schema contract","Normalize payload keys (camelCase/snake_case) before validation"],"tags":["validation","required-field","typescript"],"backgroundTag":"schema-validation-failed","analyzedSha":"58d857988fcfac6986206bca2b2fe223aa437e4b","analyzedAt":"2026-08-26T11:55:59.350Z","schemaVersion":2},"datasetVersion":"2026-08-26T14:46:13.012Z"}