mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Add message to formatter SyntaxError (#5881)
**Summary** Add a static string error message to the formatter syntax error so we can disambiguate where the syntax error came from **Test Plan** No fixed tests, we don't expect this to occur, but it helped with transformers syntax error debugging: ``` Error: Failed to format node Caused by: syntax error: slice first colon token was not a colon ```
This commit is contained in:
parent
46a17d11f3
commit
63ed7a31e8
6 changed files with 38 additions and 13 deletions
|
@ -162,18 +162,22 @@ pub(crate) fn find_colons(
|
|||
let after_lower = lower
|
||||
.as_ref()
|
||||
.map_or(range.start(), |lower| lower.range().end());
|
||||
let first_colon =
|
||||
first_non_trivia_token(after_lower, contents).ok_or(FormatError::SyntaxError)?;
|
||||
let first_colon = first_non_trivia_token(after_lower, contents).ok_or(
|
||||
FormatError::syntax_error("Din't find any token for slice first colon"),
|
||||
)?;
|
||||
if first_colon.kind != TokenKind::Colon {
|
||||
return Err(FormatError::SyntaxError);
|
||||
return Err(FormatError::syntax_error(
|
||||
"slice first colon token was not a colon",
|
||||
));
|
||||
}
|
||||
|
||||
let after_upper = upper
|
||||
.as_ref()
|
||||
.map_or(first_colon.end(), |upper| upper.range().end());
|
||||
// At least the closing bracket must exist, so there must be a token there
|
||||
let next_token =
|
||||
first_non_trivia_token(after_upper, contents).ok_or(FormatError::SyntaxError)?;
|
||||
let next_token = first_non_trivia_token(after_upper, contents).ok_or(
|
||||
FormatError::syntax_error("Din't find any token for slice second colon"),
|
||||
)?;
|
||||
let second_colon = if next_token.kind == TokenKind::Colon {
|
||||
debug_assert!(
|
||||
next_token.range.start() < range.end(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue