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:
@@ -117,14 +117,19 @@ fn are_with_items_parenthesized(
|
||||
with: &AnyStatementWith,
|
||||
context: &PyFormatContext,
|
||||
) -> FormatResult<bool> {
|
||||
let first_with_item = with.items().first().ok_or(FormatError::SyntaxError)?;
|
||||
let first_with_item = with
|
||||
.items()
|
||||
.first()
|
||||
.ok_or(FormatError::syntax_error("Expected at least one with item"))?;
|
||||
let before_first_with_item = TextRange::new(with.start(), first_with_item.start());
|
||||
|
||||
let mut tokenizer = SimpleTokenizer::new(context.source(), before_first_with_item)
|
||||
.skip_trivia()
|
||||
.skip_while(|t| t.kind() == TokenKind::Async);
|
||||
|
||||
let with_keyword = tokenizer.next().ok_or(FormatError::SyntaxError)?;
|
||||
let with_keyword = tokenizer.next().ok_or(FormatError::syntax_error(
|
||||
"Expected a with keyword, didn't find any token",
|
||||
))?;
|
||||
|
||||
debug_assert_eq!(
|
||||
with_keyword.kind(),
|
||||
|
||||
Reference in New Issue
Block a user