sickn33/agentic-awesome-skills · warning · Error

Age must be positive

Error message

Age must be positive

What it means

Thrown by the throw-based validateUser example in fp-pragmatic when `age` is a number but is negative. It represents a range/semantic check layered after the type check, and the skill contrasts it with an Either pipeline that surfaces the same failure without exceptions.

Source

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

  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')
    ),
    E.bind('age', ({ obj }) =>

View on GitHub (pinned to 58d857988f)

Solutions

  1. Clamp or reject negative values at the input layer (min='0' on numeric inputs)
  2. Validate with a boundary-aware schema (zod .nonnegative() / io-ts brand) before business logic
  3. Return the error via Either/Result instead of throwing, as the skill's 'After' version does

Example fix

// before
if (obj.age < 0) throw new Error('Age must be positive')

// after
const ageCheck = (obj: Record<string, unknown>) =>
  typeof obj.age === 'number' && obj.age >= 0
    ? E.right(obj as User)
    : E.left('Age must be positive')
Defensive patterns

Strategy: validation

Validate before calling

const isValidAge = (a: unknown) => typeof a === 'number' && Number.isFinite(a) && a >= 0

Type guard

const hasNonNegativeAge = (x: unknown): x is { age: number } =>
  typeof x === 'object' && x !== null && typeof (x as any).age === 'number' && (x as any).age >= 0

Prevention

When it happens

Trigger: Calling validateUser with an object whose email is valid and age is a negative number, e.g. { email: 'a@b.c', age: -1 }.

Common situations: Test fixtures with sentinel values like -1; arithmetic that computes age from dates with an inverted subtraction; free-text numeric fields accepting minus signs.

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/0e87f27908e29d28. Report an issue: GitHub.