sickn33/agentic-awesome-skills · warning · Error

Age required

Error message

Age required

What it means

This error is thrown by the 'Before' (throw-based) validation example in the fp-pragmatic skill. It fires when the input object exists but its `age` field is not a number (missing, string, null, etc.). The skill shows it as the anti-pattern to replace with an fp-ts Either-based validator that returns the first error as a value.

Source

Thrown at skills/fp-pragmatic/SKILL.md:469

pipe(
  getManagerEmail(employee),
  O.fold(
    () => sendToDefault(),
    (email) => sendTo(email)
  )
)
```

### Validation with Multiple Checks

```typescript
// Before: Throws on first error
function validateUser(data: unknown): User {
  if (!data || typeof data !== 'object') throw new Error('Must be object')
  const obj = data as Record<string, unknown>
  if (typeof obj.email !== 'string') throw new Error('Email required')
  if (!obj.email.includes('@')) throw new Error('Invalid email')
  if (typeof obj.age !== 'number') throw new Error('Age required')
  if (obj.age < 0) throw new Error('Age must be positive')
  return obj as User
}

// After: Returns first error, type-safe
const validateUser = (data: unknown): E.Either<string, User> =>
  pipe(
    E.Do,
    E.bind('obj', () =>
      typeof data === 'object' && data !== null
        ? E.right(data as Record<string, unknown>)
        : E.left('Must be object')
    ),
    E.bind('email', ({ obj }) =>
      typeof obj.email === 'string' && obj.email.includes('@')
        ? E.right(obj.email)
        : E.left('Valid email required')
    ),

View on GitHub (pinned to 58d857988f)

Solutions

  1. Coerce or parse the age field (Number(obj.age)) before validation if the source is a form or query param
  2. Add a schema check (zod/io-ts) at the API boundary so age is guaranteed numeric before it reaches validateUser
  3. Refactor to the skill's Either version so the error is returned as a value instead of thrown

Example fix

// before
if (typeof obj.age !== 'number') throw new Error('Age required')

// after (Either-based, first error as value)
const validateUser = (data: unknown): E.Either<string, User> =>
  pipe(
    // ...checks returning E.left('Age required') when age is not a number
  )
Defensive patterns

Strategy: type-guard

Validate before calling

const hasNumberAge = (x: unknown): boolean =>
  typeof x === 'object' && x !== null && typeof (x as any).age === 'number'

Type guard

const hasAge = (x: unknown): x is { age: number } =>
  typeof x === 'object' && x !== null && typeof (x as Record<string, unknown>).age === 'number'

Prevention

When it happens

Trigger: Calling validateUser(data) where data is an object with a valid email containing '@' but data.age is undefined, null, a string like '30', or NaN.

Common situations: Form submissions where age input arrives as a string from HTML forms or query strings; JSON payloads with optional fields omitted; API consumers sending partially-filled DTOs.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of sickn33/agentic-awesome-skills@58d857988f (2026-08-26). Data as JSON: /api/errors/53f0d0b5450d622f. Report an issue: GitHub.