Skip to content

Name the variable when a GRAPHARC_* env value cannot be coerced - #33

Merged
Shashankss1205 merged 1 commit into
mainfrom
fix/issue-16
Jul 31, 2026
Merged

Name the variable when a GRAPHARC_* env value cannot be coerced#33
Shashankss1205 merged 1 commit into
mainfrom
fix/issue-16

Conversation

@Shashankss1205

Copy link
Copy Markdown
Collaborator

What was wrong

A GRAPHARC_* environment variable that could not be coerced to its key's type crashed grapharc run with a raw ValueError traceback — exit 1 (the "ran and the answer was negative" code), empty stdout, traceback on stderr — breaking the documented --json contract that a failure is one parseable document on stdout and exit 2 means "could not run at all". A CI gate on --check-only would read that as "topology refused" when the truth was GRAPHARC_MAX_TOKENS=unlimited exported in the job environment. grapharc plan swallowed the ValueError in its broad handler and mislabelled it could not build the plan: invalid literal for int() with base 10: 'abc' — naming neither the variable nor the shell as the place to look.

The fix

Settings.resolve (grapharc/cli/config.py) now wraps the env coercion and raises ConfigError on ValueError, mirroring the wording the file layer already uses five lines down for the same mistake:

GRAPHARC_MAX_TOKENS must be int, got 'unlimited'

Nothing else needed touching: every command that resolves settings already catches ConfigError and routes it through fail(...) with exit 2, so run --json now emits a single "ok": false document on stdout with stderr empty, and plan reports the named message instead of "could not build the plan".

Tests

Three new tests beside the existing config tests in tests/test_config.py, all red against the unfixed source:

  • resolve on an int key with GRAPHARC_MAX_TOKENS=unlimited raises ConfigError naming the variable, the expected type and the given value
  • grapharc run … --check-only --json under that environment exits 2 with one "ok": false document on stdout and empty stderr
  • grapharc plan --json under GRAPHARC_MAX_ROUNDS=abc reports the named message, not the planner-flavoured one

Valid env values keep working and still report "env" in the provenance sources (pinned by the existing precedence tests). No README/cookbook output changed. uv run pytest green, uv run ruff check . clean.

Out of scope, per the issue: precedence order, empty-string env handling, new KEYS, bool handling.

Fixes #16

🤖 Generated with Claude Code

A non-numeric GRAPHARC_MAX_TOKENS crashed grapharc run with a raw
ValueError traceback, exit 1 and an empty stdout — so a CI gate on
--check-only read "topology refused" when the truth was "someone
exported GRAPHARC_MAX_TOKENS=unlimited in the job environment". plan
did not traceback, but its broad handler relabelled the failure
"could not build the plan: invalid literal…", pointing the reader at
the model rather than their shell.

Settings.resolve now wraps the env coercion and raises ConfigError
with the wording the file layer already uses for the same mistake:
GRAPHARC_MAX_TOKENS must be int, got 'unlimited'. An exported
variable is invisible on the command line, which is exactly why the
error must say which one it was. Every caller already catches
ConfigError and routes it through fail(...) with exit 2, so in --json
mode the failure is one parseable document on stdout with stderr
empty — nothing else needed touching.

Fixes #16

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Shashankss1205
Shashankss1205 merged commit 266d6a5 into main Jul 31, 2026
6 checks passed
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.

cli: a non-numeric GRAPHARC_* environment value crashes grapharc run with a ValueError traceback

1 participant