Skip to content

Refuse a spec that does not parse, instead of a loader traceback (#200) - #258

Open
tyza66 wants to merge 1 commit into
LightconeResearch:mainfrom
tyza66:fix/plan-validate-unparseable-yaml
Open

tyza66 wants to merge 1 commit into
LightconeResearch:mainfrom
tyza66:fix/plan-validate-unparseable-yaml

Conversation

@tyza66

@tyza66 tyza66 commented Oct 22, 2026

Copy link
Copy Markdown

Fixes #200.

The bug

A spec that does not parse escaped as a raw yaml.scanner.ScannerError, so
lc status and lc materialize --check tracebacked. plan._validate is the
gate that turns a bad spec into ASTRA's own errors, but it only catches what
validation reports — a file that is not YAML at all fails inside
astra.helpers.load_yaml before there is anything to validate, so the
ScannerError escapes the gate and the CLI, which only translates a
ProjectError at the _EngineErrorGroup boundary. lc materialize masked it
only because the dirty-tree refusal fires first.

The fix

One try/except yaml.YAMLError around the problems construction and the
universe loop in plan._validate, setting problems = [str(exc)]. The parse
error joins the same list the gate already renders, so the existing header and
two-space indentation carry it and no new rendering is added:

Error: .../astra.yaml does not validate, so there is nothing to materialize from it:
  mapping values are not allowed here
  in ".../astra.yaml", line 6, column 22

YAML's own error already names the file, the line and the column, which is what
the issue asked for, so it is reused verbatim rather than rebuilt from
problem_mark. Universes are covered for free: validate_universe_file loads
both the analysis and the universe, so every file is parsed inside the gate,
and the load_yaml calls build makes afterwards are then safe.

Tests

  • test_a_spec_that_is_not_yaml_is_a_clean_error and
    test_a_universe_that_is_not_yaml_is_a_clean_error in tests/test_plan.py.
  • test_status_on_a_spec_that_is_not_yaml_is_a_clean_error in
    tests/test_cli.py pins the CLI surface: exit 1, does not validate in the
    output, no traceback.

What I ran on Windows: ruff check src/ tests/ is clean, and mypy src/
reports no new errors (the 49 it does report are pre-existing POSIX-attribute
and fcntl/getuid failures in _sandbox_exec.py, engine/container.py and
engine/compute/, present on main too). tests/test_plan.py and
tests/test_cli.py together are 82 passed, 1 failed, where the failure is
test_a_declared_input_outside_the_project_keeps_its_absolute_path comparing a
Windows backslash path against a POSIX one — also failing on main. Across a
16-file subset, 528 passed and 72 failed, and the same 72 fail identically on
pristine main. The container and compute integration suites, plus
test_compute_local.py / test_compute_slurm.py, do not run on Windows, so
this PR's CI is their real run.

Disclosure

This change was written with AI assistance, using
Alpha.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 22:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

…htconeResearch#200)

`lc status` and `lc materialize --check` tracebacked out of a malformed
`astra.yaml`. `plan._validate` reports what ASTRA's *validation* finds,
but a file that is not YAML at all fails inside the loader, before there
is anything to validate — so the `ScannerError` escapes the gate, and the
CLI shows a traceback instead of the one-line error the group boundary
translates a `ProjectError` into.

Fold `yaml.YAMLError` into the same `problems` list the gate already
renders, so the existing header and the two-space indentation carry the
parse error too. The loader's own error already names the file, the line
and the column, which is where the fix goes, so it needs no reformatting.
Universes are parsed inside the gate as well, since
`validate_universe_file` loads both files, so a broken universe reaches
the same clean error.

- `test_a_spec_that_is_not_yaml_is_a_clean_error` and
  `test_a_universe_that_is_not_yaml_is_a_clean_error` in `tests/test_plan.py`.
- `test_status_on_a_spec_that_is_not_yaml_is_a_clean_error` in
  `tests/test_cli.py` pins the CLI surface: exit 1, no traceback.

🤖 Generated with [Alpha](https://github.com/Mutantcat-Working-Group/Alpha)
@tyza66
tyza66 force-pushed the fix/plan-validate-unparseable-yaml branch from 59a692f to 5776a31 Compare November 4, 2026 02:05

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A malformed astra.yaml tracebacks out of lc status and lc materialize --check

2 participants