sickn33/agentic-awesome-skills · error · Error

Invalid age

Error message

Invalid age

What it means

Thrown by the Before imperative parseAge example in the fp-pragmatic skill (skills/fp-pragmatic/SKILL.md:113) when parseInt(input, 10) yields NaN, i.e. the input is not parseable as an integer. The doc contrasts it with an Either<string, number> return type that surfaces the failure in the signature.

Source

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

```

**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

  1. Validate and trim input before parsing (reject empty and non-numeric strings at the boundary)
  2. Adopt the doc AFTER version: return E.Either<string, number> and let callers handle Left
  3. Use a schema library (zod/io-ts) to parse and validate in one step

Example fix

// before
function parseAge(input: string): number {
  const age = parseInt(input, 10)
  if (isNaN(age)) throw new Error('Invalid age')
  return age
}

// after
function parseAge(input: string): E.Either<string, number> {
  const age = parseInt(input, 10)
  return isNaN(age) ? E.left('Invalid age') : E.right(age)
}
Defensive patterns

Strategy: validation

Validate before calling

const trimmed = input.trim()
if (!/^-?[0-9]+$/.test(trimmed)) {
  return badRequest('age must be an integer')
}

Type guard

const isParsableInt = (s: string): boolean => /^-?[0-9]+$/.test(s.trim())

Prevention

When it happens

Trigger: Calling parseAge with an empty string, alphabetic garbage like abc, leading non-numeric text, a nullish value coerced to string, or whitespace-only input.

Common situations: Unvalidated form fields or query params passed straight to parsing; locale differences (commas as decimal separators); ages arriving as free text from third-party APIs.

Related errors


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