-
Notifications
You must be signed in to change notification settings - Fork 1
Sanitize scenario exception reports #10
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,24 @@ def public_path(path: Path) -> str: | |
| return str(path) | ||
|
|
||
|
|
||
| def public_exception_message(exc: Exception, path: Path) -> str: | ||
| """Return an exception message with local filesystem paths redacted.""" | ||
|
|
||
| message = str(exc) or type(exc).__name__ | ||
| replacements = {str(path): public_path(path)} | ||
| filename = getattr(exc, "filename", None) | ||
| filename2 = getattr(exc, "filename2", None) | ||
| for candidate in (filename, filename2): | ||
| if candidate: | ||
| candidate_path = Path(candidate) | ||
| replacements[str(candidate_path)] = public_path(candidate_path) | ||
|
|
||
| for raw, safe in replacements.items(): | ||
| if raw: | ||
| message = message.replace(raw, safe) | ||
| return message | ||
|
Comment on lines
+40
to
+55
|
||
|
|
||
|
|
||
| def load_yaml(path: Path) -> dict[str, Any]: | ||
| data = yaml.safe_load(path.read_text(encoding="utf-8")) | ||
| if not isinstance(data, dict): | ||
|
|
@@ -55,7 +73,12 @@ def validate_scenario(path: Path) -> dict[str, Any]: | |
| try: | ||
| data = load_yaml(path) | ||
| except Exception as exc: # noqa: BLE001 - report parse errors as validation failures | ||
| return {"path": str(path), "status": "failed", "errors": [str(exc)], "warnings": []} | ||
| return { | ||
| "path": public_path(path), | ||
| "status": "failed", | ||
| "errors": [public_exception_message(exc, path)], | ||
| "warnings": [], | ||
| } | ||
|
|
||
| required = [ | ||
| "scenario_id", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new public-safe tests cover POSIX absolute paths, but they won’t catch the common
OSError.__str__behavior of rendering filenames viarepr(filename)(escaping backslashes). Adding a regression that constructs aFileNotFoundError(..., filename="C:\\tmp\\missing.yaml")and asserts the redaction removes both the raw andrepr-escaped forms would help ensure Windows-style paths are also public-safe.