Skip to content

Commit 00a533d

Browse files
authored
fix: simplify native TOML config reading and restore error columns (#1085)
* fix: simplify native TOML config reading and restore error columns * test: update the failure-corpus count after removing the BOM failure case * test: expect TOML nesting past the reader's limit to be rejected * test: assert the too-deep TOML error through its test case * chore: cover the 3,000-model lineage RSS guard in the 0.156.0 memory exception
1 parent 11c2c53 commit 00a533d

22 files changed

Lines changed: 269 additions & 728 deletions

File tree

‎crates/sqlbuild-config/src/toml/_helpers/conversion.rs‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,30 @@ fn table(entries: &Table, depth: usize) -> Result<Positioned, ConfigError> {
156156
Ok(ordered_map(converted))
157157
}
158158

159+
/// The one-based line and character column of byte `offset` in `text`.
160+
pub(crate) fn line_and_column(text: &str, offset: usize) -> (usize, usize) {
161+
let before = text.get(..offset).unwrap_or(text);
162+
let line_start = before.rfind('\n').map_or(0, |index| index + 1);
163+
(
164+
before.matches('\n').count() + 1,
165+
before[line_start..].chars().count() + 1,
166+
)
167+
}
168+
169+
/// A syntax error located at byte `offset` of `text`.
170+
pub(crate) fn syntax_error(text: &str, offset: usize, message: impl Into<String>) -> ConfigError {
171+
let (line, column) = line_and_column(text, offset);
172+
ConfigError::new(ConfigErrorKind::Syntax, message).at(line, column)
173+
}
174+
159175
/// Parse `text` and convert its root table.
160176
pub(crate) fn parse_document(text: &str) -> Result<ConfigValue, ConfigError> {
161177
let document = Document::parse(text).map_err(|error| {
162-
let offset = error.span().map_or(0, |span| span.start);
163-
ConfigError {
164-
kind: ConfigErrorKind::Syntax,
165-
message: error.message().to_owned(),
166-
line: Some(text.get(..offset).unwrap_or(text).matches('\n').count() + 1),
167-
column: None,
168-
}
178+
syntax_error(
179+
text,
180+
error.span().map_or(0, |span| span.start),
181+
error.message(),
182+
)
169183
})?;
170184
table(document.as_table(), 0).map(|(converted, _)| converted)
171185
}

‎crates/sqlbuild-config/src/toml/_helpers/integers.rs‎

Lines changed: 0 additions & 121 deletions
This file was deleted.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
pub(crate) mod conversion;
2-
pub(crate) mod integers;
3-
pub(crate) mod namespaces;
42
pub(crate) mod reading;
53
pub(crate) mod version;

0 commit comments

Comments
 (0)