sickn33/agentic-awesome-skills · warning · Error

Age must be a number

Error message

Age must be a number

What it means

Second field guard in fp-refactor's validateUser: the object passed the name check but `age` is missing or not a number. The surrounding code even wraps the throws in a redundant try/catch that rethrows — itself a refactor target in the skill.

Source

Thrown at skills/fp-refactor/SKILL.md:76

function parseJSON(input: string): unknown {
  try {
    return JSON.parse(input);
  } catch (error) {
    throw new Error(`Invalid JSON: ${error}`);
  }
}

function validateUser(data: unknown): User {
  try {
    if (!data || typeof data !== 'object') {
      throw new Error('Data must be an object');
    }
    const obj = data as Record<string, unknown>;
    if (typeof obj.name !== 'string') {
      throw new Error('Name is required');
    }
    if (typeof obj.age !== 'number') {
      throw new Error('Age must be a number');
    }
    return { name: obj.name, age: obj.age };
  } catch (error) {
    throw error;
  }
}

// Usage with nested try-catch
function processUserInput(input: string): User | null {
  try {
    const data = parseJSON(input);
    const user = validateUser(data);
    return user;
  } catch (error) {
    console.error('Failed to process user:', error);
    return null;
  }
}

View on GitHub (pinned to 58d857988f)

Solutions

  1. Parse and coerce age at the edge (Number(), parseInt with NaN check) when the source is textual
  2. Declare age as required number in a shared schema and validate payloads before they reach business code
  3. Return the error as a value with Either instead of throwing

Example fix

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

// after
const parseAge = (v: unknown): E.Either<string, number> =>
  typeof v === 'number' && Number.isFinite(v) ? E.right(v) : E.left('Age must be a number')
Defensive patterns

Strategy: validation

Validate before calling

const toNumber = (v: unknown): number | null => {
  const n = typeof v === 'number' ? v : Number(v)
  return Number.isFinite(n) ? n : null
}

Type guard

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

Prevention

When it happens

Trigger: validateUser({ name: 'Bob' }) with age omitted, or age as '30', null, or boolean.

Common situations: HTML form values arriving as strings; CSV/Excel imports with blank cells; JSON from loose backends that allow age: null.

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