Skip to content

Commit 00be2c4

Browse files
committed
fix: hide non-primary span errors in output
1 parent 0cd3be4 commit 00be2c4

File tree

4 files changed

+8
-272
lines changed

4 files changed

+8
-272
lines changed

exts/rust-code-runner/generated.rs

Lines changed: 0 additions & 259 deletions
This file was deleted.

exts/rust-code-runner/rust_examples_aggregate.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
import logging
33
import re
44

5-
logger = logging.getLogger('sphinx')
6-
# reducing errors temporarly for dev
7-
logger.setLevel(logging.ERROR)
8-
95
class ExecuteRustExamples(SphinxError):
106
category = "ExecuteRustExamples Error"
117

exts/rust-code-runner/rustc.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,26 @@ def parse_rustc_json(stderr: str, file_path):
5656
continue
5757

5858
if diagnostic.get("level") != "error":
59-
continue # skip warnings and notes
59+
continue
6060

6161
message = diagnostic.get("message", "")
6262
spans = diagnostic.get("spans", [])
6363

64-
# Try to find a span in the current file
64+
# Prefer the primary span in the current file
6565
for span in spans:
66-
if span["file_name"] == file_path:
66+
if span.get("is_primary") and span["file_name"] == file_path:
6767
line_num = span["line_start"]
6868
label = span.get("label", "")
6969
print(f"error: line {line_num}: {message}")
7070
if label:
7171
print(f"--> {label}")
7272
print("=" * 25)
73-
snippet = print_code_snippet(file_path, line_num, context=3)
73+
snippet = print_code_snippet(file_path, line_num, context=8)
7474
print(snippet)
7575
print("=" * 25)
76-
return # we return because we only print the first error--in json format there can be multiple error messages for 1 error-- if you want to see them comment this line.
76+
return # we return because we only print the first error--in json format there can be multiple error messages(primary and non primary) for 1 error-- if you want to see them comment this line.
7777

78-
# If no span in the file, still print the error
78+
# fallback: print the error message if no span in the current file
7979
print(f"error: {message}")
8080
return
8181

@@ -105,8 +105,8 @@ def check_rust_test_errors(app, exception):
105105
if result.returncode != 0:
106106
print("--- rustc Errors/Warnings ---")
107107
parse_rustc_json(result.stderr, app.output_rust_file)
108-
print("--- rustc Output ---")
109-
print(result.stdout)
108+
# print("--- rustc Output ---")
109+
# print(result.stdout)
110110

111111
else:
112112
print("--- rustc Output ---")

src/coding-guidelines/macros.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ Macros
371371
372372
#[tokio::main] // non-compliant
373373
async fn main() {
374-
375374
}
376375
377376
.. compliant_example::

0 commit comments

Comments
 (0)