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:
@@ -91,7 +91,9 @@ impl Format<PyFormatContext<'_>> for FormatStringContinuation<'_> {
|
||||
continue;
|
||||
}
|
||||
Err(_) => {
|
||||
return Err(FormatError::SyntaxError);
|
||||
return Err(FormatError::syntax_error(
|
||||
"Unexpected lexer error in string formatting",
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -167,7 +169,9 @@ impl Format<PyFormatContext<'_>> for FormatStringPart {
|
||||
let prefix = StringPrefix::parse(string_content);
|
||||
let after_prefix = &string_content[usize::from(prefix.text_len())..];
|
||||
|
||||
let quotes = StringQuotes::parse(after_prefix).ok_or(FormatError::SyntaxError)?;
|
||||
let quotes = StringQuotes::parse(after_prefix).ok_or(FormatError::syntax_error(
|
||||
"Didn't find string quotes after prefix",
|
||||
))?;
|
||||
let relative_raw_content_range = TextRange::new(
|
||||
prefix.text_len() + quotes.text_len(),
|
||||
string_content.text_len() - quotes.text_len(),
|
||||
|
||||
Reference in New Issue
Block a user