sickn33/agentic-awesome-skills · error · Error
Age cannot be negative
Error message
Age cannot be negative
What it means
Second guard in the same fp-pragmatic parseAge example (skills/fp-pragmatic/SKILL.md:114): thrown when the input parses to a number but that number is negative, i.e. a semantically invalid age that survives the NaN check.
Source
Thrown at skills/fp-pragmatic/SKILL.md:114
**Plain language translation:**
- `O.fromNullable(x)` = "wrap this value, treating null/undefined as 'nothing'"
- `O.flatMap(fn)` = "if we have something, apply this function"
- `O.getOrElse(() => default)` = "unwrap, or use this default if nothing"
### 3. Either: Make Errors Explicit
Stop throwing exceptions for expected failures. Return errors as values.
```typescript
import * as E from 'fp-ts/Either'
import { pipe } from 'fp-ts/function'
// Before: Hidden failure mode
function parseAge(input: string): number {
const age = parseInt(input, 10)
if (isNaN(age)) throw new Error('Invalid age')
if (age < 0) throw new Error('Age cannot be negative')
return age
}
// After: Errors are visible in the type
function parseAge(input: string): E.Either<string, number> {
const age = parseInt(input, 10)
if (isNaN(age)) return E.left('Invalid age')
if (age < 0) return E.left('Age cannot be negative')
return E.right(age)
}
// Using it
const result = parseAge(userInput)
if (E.isRight(result)) {
console.log(`Age is ${result.right}`)
} else {
console.log(`Error: ${result.left}`)
}View on GitHub (pinned to 58d857988f)
Solutions
- Add domain constraints to the Either version: chain a non-negative check that returns E.left with a cannot-be-negative message
- Constrain at the input layer: number input with min=0 in forms, schema validation with a nonnegative rule
- Audit data sources if negatives appear unexpectedly (sign flips, unit confusion)
Example fix
// before
if (age < 0) throw new Error('Age cannot be negative')
return age
// after
return age < 0
? E.left('Age cannot be negative')
: E.right(age) Defensive patterns
Strategy: validation
Validate before calling
const age = Number(input)
if (!Number.isInteger(age) || age < 0) {
return badRequest('age must be a non-negative integer')
} Type guard
const isNonNegativeInt = (n: unknown): n is number => typeof n === 'number' && Number.isInteger(n) && n >= 0
Prevention
- Encode domain bounds (min/max) in a schema, not ad-hoc ifs
- Use number inputs with min=0 on forms
- Chain range checks in the Either version so all errors surface together
When it happens
Trigger: parseAge with -5 or any input whose parsed integer is below zero; also decimal strings that parseInt truncates but that still yield a value of -1 or less.
Common situations: Users typing a minus sign or negative numbers in age fields; sign errors in upstream data feeds; test fixtures using sentinel negative values.
Related errors
- Invalid range "${t}" in ${fieldDef.name}
- Expected 5 fields (got ${parts.length}). Format: minute hour
- Invalid age
- Invalid JSON: ${error}
- Value ${v} out of range for ${fieldDef.name} (${fieldDef.min
AI-assisted analysis of sickn33/agentic-awesome-skills@58d857988f (2026-08-26).
Data as JSON: /api/errors/67002ab60c657c9d.
Report an issue: GitHub.