Skip to content

fix: replace bare excepts in tg-set-prompt, structured-data cleanup and API docs generator - #1114

Closed
Thorsrud22 wants to merge 1 commit into
trustgraph-ai:release/v2.9from
Thorsrud22:fix/bare-except-cli-docs
Closed

Thorsrud22 wants to merge 1 commit into
trustgraph-ai:release/v2.9from
Thorsrud22:fix/bare-except-cli-docs

Conversation

@Thorsrud22

@Thorsrud22 Thorsrud22 commented Sep 13, 2026

Copy link
Copy Markdown

Refs #783. Takes the slice I claimed on the issue: three of the remaining bare except: clauses outside tests/ on release/v2.9.

Summary

  • trustgraph-cli/trustgraph/cli/set_prompt.py:129: the --schema parse catches json.JSONDecodeError only, and chains it (raise ... from e) so the position of the JSON error is kept on the RuntimeError.
  • trustgraph-cli/trustgraph/cli/load_structured_data.py:167: the temp-descriptor cleanup in the finally block catches OSError only (which covers FileNotFoundError).
  • docs/generate-api-docs.py:112: the inspect.signature fallback catches TypeError and ValueError, the two exceptions it documents raising, instead of everything.

Behaviour for the normal paths is unchanged; only KeyboardInterrupt/SystemExit (and unrelated bugs) now propagate instead of being silently swallowed.

Tests

  • New tests/unit/test_cli/test_set_prompt_errors.py: invalid --schema JSON produces the existing "JSON schema must be valid JSON" message and never calls the API; a valid schema is passed through parsed; a KeyboardInterrupt raised inside the parse propagates.
  • PYTHONPATH=trustgraph-cli:trustgraph-base python -m pytest tests/unit/test_cli/test_set_prompt_errors.py tests/unit/test_cli/test_load_structured_data.py: 10 passed, 2 skipped (pre-existing skips).
  • python -m py_compile on the three edited files.

Not touched: load_doc_embeds.py / save_doc_embeds.py (claimed by @chiruu12) and the two ontology files, which are still open for someone else.

@github-actions

github-actions Bot commented Sep 13, 2026

Copy link
Copy Markdown

Contributor License Agreement

Thank you for your contribution! Before we can accept it, the following contributor(s) must sign our CLA:

@Thorsrud22

Please read the appropriate agreement:

  • Contributing as an individual? Read the Individual CLA
  • Contributing on behalf of a company or organisation? Read the Entity CLA

Once you have read the appropriate agreement, post the following as a comment on this PR (copy and paste exactly):

I have read the CLA Document and I hereby sign the CLA

The bot will record your signature and update this PR automatically.

…nd API docs generator

Three of the remaining bare `except:` clauses from trustgraph-ai#783, each swallowing
KeyboardInterrupt and SystemExit:

- trustgraph-cli/trustgraph/cli/set_prompt.py: the --schema JSON parse
  now catches json.JSONDecodeError only, and chains it onto the
  RuntimeError so the parse position is not lost.
- trustgraph-cli/trustgraph/cli/load_structured_data.py: the temp
  descriptor cleanup catches OSError only.
- docs/generate-api-docs.py: the inspect.signature fallback catches the
  two errors it actually raises, TypeError and ValueError.

Tests for tg-set-prompt cover the invalid-JSON error message, a valid
schema being passed through, and KeyboardInterrupt propagating out of
the parse.

Refs trustgraph-ai#783
@Thorsrud22
Thorsrud22 force-pushed the fix/bare-except-cli-docs branch from de88353 to 7105ce9 Compare September 13, 2026 18:58
@cybermaggedon

Copy link
Copy Markdown
Contributor

@Thorsrud22 are you able to action the CLA?

@Thorsrud22
Thorsrud22 force-pushed the fix/bare-except-cli-docs branch from 7105ce9 to c6b3d0a Compare September 16, 2026 18:26
@Thorsrud22

Copy link
Copy Markdown
Author

Thanks for asking, @cybermaggedon. I'd rather not sign a CLA, so I'm closing this. The changes are small and self-contained, so anyone is welcome to pick them up. Sorry for not noticing the CLA requirement before opening it.

@Thorsrud22 Thorsrud22 closed this Sep 16, 2026
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.

2 participants