fix(cli): surface YAML and AsyncAPI errors from docs serve#2874
Open
SarthakB11 wants to merge 1 commit into
Open
fix(cli): surface YAML and AsyncAPI errors from docs serve#2874SarthakB11 wants to merge 1 commit into
docs serve#2874SarthakB11 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Refs #2709 (diagnostic portion).
Per @Sehat1137's recommendation on #2858 ("a smaller PR limited to that behavior, with deterministic parsing and regression tests"), this is the diagnostic-only redo: no new CLI options, no parser plugin, default
yaml.safe_loadpreserved. The pluggable-parser proposal from #2709 is intentionally deferred per maintainer feedback.faststream docs serve <asyncapi.yaml>previously collapsed three different failure modes into one opaqueSCHEMA_NOT_SUPPORTEDmessage:yaml.safe_loadran outside anytry, so the user either got an uncaught traceback or, more often, a downstream pydantic failure on the garbage that partial parsing produced.contextlib.suppress(ValidationError), so there was no indication of which schema version was tried or why it failed.protocolVersion: 3.2(parsed as afloat, rejected by AsyncAPI'sstringtype) gave no hint that the value just needed quoting. This is the exact repro from Bug:PyYAMLcannot correct parseasyncapi.yaml#2709.Fix
Edits only
_parse_and_serveinfaststream/_internal/cli/docs.py:yaml.safe_loadintry / except yaml.YAMLError, echo the parser exception, exit 1.suppress(ValidationError)with an explicit collector that records(version_label, ValidationError). When neither v3.0 nor v2.6 validates, printSCHEMA_NOT_SUPPORTEDfollowed by both per-version error blocks on stderr.type == "string_type"and anint | float | boolinput, append a one-line hint pointing at the location and suggesting YAML quoting (e.g.'3.2').Default parser is unchanged.
_parse_and_serve's public signature is untouched.dto.pyis untouched. No new modules, no parser registry, no--yaml-parserflag.Tests
Two regression tests in
tests/cli/test_asyncapi_docs.py:test_serve_asyncapi_yaml_unquoted_scalar_reports_hintmutates the existingyaml_asyncapi_docfixture toprotocolVersion: 3.2, asserts exit code 1 and the v3.0 / v2.6 error enumeration plus the quoting hint.test_serve_asyncapi_reports_yaml_parse_errorfeeds malformed YAML (foo: [unclosed) and asserts the parser exception is surfaced rather than swallowed.Both follow the existing
faststream_cli + generate_template + wait_for_stderrpattern in the same file.Type of change
Checklist
just lintshows no errors)just test-coveragejust static-analysis