-
Notifications
You must be signed in to change notification settings - Fork 1
Add incomplete-result signaling on parse failure (#67) #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
93dea04
initial implementation for replacing except-pass
bradjin8 7e6dca2
fix: test failure with bubble none and pytest missing
bradjin8 70afd81
fix: Broaden the decode guard to keep malformed KV rows non-fatal.
bradjin8 18a7509
fix: replace remaining print and pattern.
bradjin8 eb45566
initial implementation
bradjin8 bc79ce6
fix: review comments
bradjin8 62b007c
fix: review comments
bradjin8 edaf3b9
fix: review comments
bradjin8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| @dataclass | ||
| class ParseWarningCollector: | ||
| """Accumulates parse failures skipped during bubble/composer processing.""" | ||
|
|
||
| composers_skipped: int = 0 | ||
| bubbles_skipped: int = 0 | ||
|
|
||
| def record_composer_skipped(self, count: int = 1) -> None: | ||
| if count > 0: | ||
| self.composers_skipped += count | ||
|
|
||
| def record_bubble_skipped(self, count: int = 1) -> None: | ||
| if count > 0: | ||
| self.bubbles_skipped += count | ||
|
|
||
| @property | ||
| def has_warnings(self) -> bool: | ||
| return self.composers_skipped > 0 or self.bubbles_skipped > 0 | ||
|
|
||
| def to_api_list(self) -> list[dict]: | ||
| """Structured warnings for JSON API responses (issue #67).""" | ||
| warnings: list[dict] = [] | ||
| if self.composers_skipped: | ||
| n = self.composers_skipped | ||
| noun = "conversation" if n == 1 else "conversations" | ||
| warnings.append({ | ||
| "type": "parse_error", | ||
| "count": n, | ||
| "detail": ( | ||
| f"{n} {noun} could not be loaded due to schema or JSON parse errors" | ||
| ), | ||
| }) | ||
| if self.bubbles_skipped: | ||
| n = self.bubbles_skipped | ||
| noun = "message" if n == 1 else "messages" | ||
| warnings.append({ | ||
| "type": "parse_error", | ||
| "count": n, | ||
| "detail": ( | ||
| f"{n} {noun} could not be loaded due to schema or JSON parse errors" | ||
| ), | ||
| }) | ||
| return warnings | ||
|
|
||
| def attach_to(self, payload: dict) -> dict: | ||
| """Add ``warnings`` to a dict response when any failures were recorded.""" | ||
| if self.has_warnings: | ||
| payload = {**payload, "warnings": self.to_api_list()} | ||
| return payload | ||
|
|
||
|
|
||
| def attach_warnings(payload: dict, warnings: list[dict]) -> dict: | ||
| """Merge pre-built warnings into a response dict.""" | ||
| if warnings: | ||
| return {**payload, "warnings": warnings} | ||
| return payload |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.