fix(cli): surface actionable errors when OpenAPI spec generation fails#7592
fix(cli): surface actionable errors when OpenAPI spec generation fails#7592DogInfantry wants to merge 2 commits into
Conversation
Follow-up to OpenBB-finance#7585. OpenBB-finance#7586 and OpenBB-finance#7589 fixed modular spec resolution and added zero-command guards to --generate-spec and --generate-extension. This covers the remaining places a bad document or unreachable server still produced a raw traceback or a silent empty session: - Interactive `openbb --server URL` startup: fetch failures now print a one-line message and exit 2 instead of a traceback, and a zero-command document aborts with the same guard used by --generate-spec instead of launching an empty REPL. - --generate-spec fetch errors (httpx transport/status, parse/bundle ValueError) are caught and reported with the source URL. - _resolve_json_pointer raises ValueError naming the pointer and the failing member instead of a bare KeyError/IndexError when an external $ref points at a missing node. - _yaml_load converts yaml.YAMLError into ValueError so malformed YAML integrates with the existing fetch_openapi fallback instead of raising a raw scanner traceback.
|
There's likely some middle ground between suppressing the Exception and traceback, and a just raw dumping the stack. For this A/B, I found that on Windows, GitHub URLs needed to have the "raw=true" query parameter in order to fetch the actual file. What's notable about the raw error is that it also doesn't actually identify the problem with the file type. What got returned was a HTML content-type which could have an error message embedded in the text or body, yet still carried a 200 status. From this PR branch, it's a little too sparse. So, maybe something like The full error: |
… mode Addresses review feedback on OpenBB-finance#7592. - The fetch stage now detects an HTML page (content-type text/html or an <!doctype html>/<html> body) before handing it to the YAML parser and raises an actionable error pointing at the raw file URL. This replaces the confusing 'Document is not valid YAML' scanner error for GitHub blob URLs, while still extracting embedded specs from Swagger UI pages. - Spec fetch failures print the one-line message by default and emit the full traceback only when OPENBB_DEBUG_MODE is set.
|
Thanks for the review. Pushed a follow-up addressing both points. HTML at the fetch stage. So the GitHub blob URL gives an actionable message instead of Traceback visibility. The failure keeps the one-line message and exit code 2 by default, and now prints the full traceback when New tests cover the HTML rejection, the embedded-spec regression, and the debug-gated traceback. |
Follow-up to #7585, as invited by @deeleeramone in #7585 (comment). #7586 and #7589 fixed the modular spec resolution and added zero-command guards to
--generate-specand--generate-extension. This PR covers the remaining places where a bad document or an unreachable server still produced a raw traceback or a silent empty session.What changed
Interactive
openbb --server URLstartup (cli/openbb_cli/cli.py)--generate-spec, instead of silently launching an empty REPL.--generate-specfetch errors (cli/openbb_cli/cli.py)httpxtransport and status errors, andValueErrorfrom parsing or bundling, are caught and reported asfailed to fetch the OpenAPI document from <url>: <cause>, exit 2.Dangling JSON pointers in external refs (
cli/openbb_cli/dispatchers/openapi_schema.py)_resolve_json_pointerpreviously raised a bareKeyError: 'foo'orIndexErrorwhen a modular spec pointed at a missing member. It now raisesValueErrornaming the pointer and the failing part, for example:OpenAPI reference pointer #/paths/~1x not found: no member '/x'.Malformed YAML (
cli/openbb_cli/dispatchers/openapi_schema.py)yaml.YAMLErrorescaped the existingexcept (json.JSONDecodeError, ValueError)handling infetch_openapi, so a broken YAML endpoint produced a raw scanner traceback._yaml_loadnow converts it toValueError("Document is not valid YAML: <first line>"), which integrates with the existing fallback logic.Tests
cli/tests/test_cli.py: fetch failure and HTTP 500 during--generate-spec; fetch failure and zero-command guard on interactive--serverstartup.cli/tests/test_dispatchers_openapi_schema.py: missing member and bad array index in_resolve_json_pointer; dangling pointer through_bundle_external_refs; malformed YAML through_parse_spec_text.All of
cli/tests/test_cli.py,cli/tests/test_dispatchers_openapi_schema.py, andcli/tests/test_dispatchers_spec.pypass locally (309 tests).