Skip to content

Commit 27a26d6

Browse files
pfnsecjuntyr
andauthored
SpannedError: Store error span (#569)
* SpannedError: Store position start and position end in span * Update CHANGELOG.md Co-authored-by: Juniper Tyree <[email protected]> * fix: SpannedError: fmt displays start and end of span if they differ * fix: errant tests and formatting * ci: Clean between Check/Clippy/Test * test: Add helpers for Position and Span error checking, and use them in all unit tests that use non-trivial Spans * fix: place unicode-segmentation and the Span::substring helpers behind an optional (non-default) feature, include substring Span checks in non-trivial integration tests --------- Co-authored-by: Juniper Tyree <[email protected]>
1 parent b7a5bfc commit 27a26d6

36 files changed

+1818
-532
lines changed

.github/workflows/ci.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,20 @@ jobs:
7777
- name: Check
7878
run: |
7979
cargo hack check --feature-powerset --no-dev-deps
80+
- name: Clean
81+
run: |
82+
cargo clean
8083
- name: Clippy
8184
run: |
8285
cargo hack clippy --feature-powerset --no-dev-deps -- -D warnings -A unknown-lints
8386
# Clippy will report lints that cannot be acted on without increasing MSRV on later versions of Rust
8487
if: ${{ matrix.rust == '1.64.0' }}
88+
- name: Clean
89+
run: |
90+
cargo clean
8591
- name: Test
8692
run: |
87-
cargo hack test --feature-powerset
93+
cargo hack test --feature-powerset --clean-per-run
8894
8995
clippy-fuzz:
9096
name: "Clippy: Fuzzer"

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### API Changes
1010

11+
- Breaking: `SpannedError` now stores the full error span in span: Span { start: Position, end: Position }`, to facilitate, e.g., language servers highlighting of syntax errors.
12+
1113
- Breaking: Added `no_std` support via a new `std` feature (enabled by default). With default features disabled, you must enable the `std` feature to access `de::from_reader`, and the `std::io` operations on `Options`, such as `from_reader`, `from_reader_seed`, `to_io_writer`, and `to_io_writer_pretty` ([#567](https://github.com/ron-rs/ron/pull/567))
1214

1315
## [0.10.1] - 2025-04-08

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ default = ["std"]
2424
integer128 = []
2525
std = ["serde/std"]
2626
indexmap = ["std", "dep:indexmap"]
27+
# Note: this feature is a gate for internal error span tests and should not be enabled by users.
28+
internal-span-substring-test = ["unicode-segmentation"]
2729

2830
[dependencies]
2931
# FIXME @juntyr remove base64 once old byte strings are fully deprecated
@@ -36,6 +38,7 @@ indexmap = { version = "2.0", default-features = false, features = ["serde"], op
3638
serde = { version = "1.0.181", default-features = false, features = ["alloc"] }
3739
serde_derive = { version = "1.0.181", default-features = false }
3840
unicode-ident = { version = "1.0", default-features = false }
41+
unicode-segmentation = { version = "1.12.0", optional = true, default-features = false }
3942

4043
[dev-dependencies]
4144
serde = { version = "1.0.181", default-features = false, features = ["std", "derive"] }

src/de/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use serde::{
1111
Deserialize,
1212
};
1313

14-
pub use crate::error::{Error, Position, SpannedError};
14+
pub use crate::error::{Error, Position, Span, SpannedError};
1515
use crate::{
1616
error::{Result, SpannedResult},
1717
extensions::Extensions,
@@ -83,7 +83,10 @@ impl<'de> Deserializer<'de> {
8383

8484
Err(SpannedError {
8585
code: err.into(),
86-
position: Position::from_src_end(valid_input),
86+
span: Span {
87+
start: Position { line: 1, col: 1 },
88+
end: Position::from_src_end(valid_input),
89+
},
8790
})
8891
}
8992

0 commit comments

Comments
 (0)