Skip to content

Friendlier YAML parse errors when working/*.yaml is malformed #3

@samson-ailabs

Description

@samson-ailabs

Currently scripts/lib/schema.mjs loads YAML with no error handling:

function loadYaml(path) {
  return yaml.load(readFileSync(path, "utf8"));
}

When working/profile.yaml or working/criteria.yaml is malformed (a stray tab, bad indentation, missing colon), the user gets a raw YAMLException from js-yaml with no file context — just something like bad indentation of a mapping entry at line 25, column 5. They have to guess which file broke.

Task: wrap loadYaml() in scripts/lib/schema.mjs to catch YAMLException and re-throw with file-aware context. js-yaml's YAMLException exposes .mark with line, column, and name properties — use these to build a friendly message.

Expected message shape:

Couldn't parse working/profile.yaml — bad indentation at line 25, column 5.
Check the YAML syntax around that line.

Acceptance:

  • Intentionally break working/profile.yaml (add a stray tab, drop a colon, etc.)
  • Run any script that loads YAML (e.g. via /argopia-survey)
  • User sees a friendly message naming the file and the offending line/column — not a raw stack trace
  • All other call sites of loadYaml() benefit automatically (it's the single chokepoint)

Scope: scripts/lib/schema.mjs is the only file that needs changing. No new dependencies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions