Skip to content

Improve error messages with additional colons #1319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3116,7 +3116,7 @@ impl<'a> Parser<'a> {
/// Report `found` was encountered instead of `expected`
pub fn expected<T>(&self, expected: &str, found: TokenWithLocation) -> Result<T, ParserError> {
parser_err!(
format!("Expected {expected}, found: {found}"),
format!("Expected: {expected}, found: {found}"),
found.location
)
}
Expand Down Expand Up @@ -11581,7 +11581,7 @@ mod tests {
assert_eq!(
ast,
Err(ParserError::TokenizerError(
"Unterminated string literal at Line: 1, Column 5".to_string()
"Unterminated string literal at Line: 1, Column: 5".to_string()
))
);
}
Expand All @@ -11593,7 +11593,7 @@ mod tests {
assert_eq!(
ast,
Err(ParserError::ParserError(
"Expected [NOT] NULL or TRUE|FALSE or [NOT] DISTINCT FROM after IS, found: a at Line: 1, Column 16"
"Expected: [NOT] NULL or TRUE|FALSE or [NOT] DISTINCT FROM after IS, found: a at Line: 1, Column: 16"
.to_string()
))
);
Expand Down
4 changes: 2 additions & 2 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl fmt::Display for Location {
write!(
f,
// TODO: use standard compiler location syntax (<path>:<line>:<col>)
" at Line: {}, Column {}",
" at Line: {}, Column: {}",
self.line, self.column,
)
}
Expand Down Expand Up @@ -1816,7 +1816,7 @@ mod tests {
use std::error::Error;
assert!(err.source().is_none());
}
assert_eq!(err.to_string(), "test at Line: 1, Column 1");
assert_eq!(err.to_string(), "test at Line: 1, Column: 1");
}

#[test]
Expand Down
20 changes: 10 additions & 10 deletions tests/sqlparser_bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ fn parse_invalid_brackets() {
bigquery_and_generic()
.parse_sql_statements(sql)
.unwrap_err(),
ParserError::ParserError("Expected (, found: >".to_string())
ParserError::ParserError("Expected: (, found: >".to_string())
);

let sql = "CREATE TABLE table (x STRUCT<STRUCT<INT64>>>)";
Expand All @@ -544,7 +544,7 @@ fn parse_invalid_brackets() {
.parse_sql_statements(sql)
.unwrap_err(),
ParserError::ParserError(
"Expected ',' or ')' after column definition, found: >".to_string()
"Expected: ',' or ')' after column definition, found: >".to_string()
)
);
}
Expand Down Expand Up @@ -1753,11 +1753,11 @@ fn parse_merge_invalid_statements() {
for (sql, err_msg) in [
(
"MERGE T USING U ON TRUE WHEN MATCHED BY TARGET AND 1 THEN DELETE",
"Expected THEN, found: BY",
"Expected: THEN, found: BY",
),
(
"MERGE T USING U ON TRUE WHEN MATCHED BY SOURCE AND 1 THEN DELETE",
"Expected THEN, found: BY",
"Expected: THEN, found: BY",
),
(
"MERGE T USING U ON TRUE WHEN NOT MATCHED BY SOURCE THEN INSERT(a) VALUES (b)",
Expand Down Expand Up @@ -1898,13 +1898,13 @@ fn parse_big_query_declare() {

let error_sql = "DECLARE x";
assert_eq!(
ParserError::ParserError("Expected a data type name, found: EOF".to_owned()),
ParserError::ParserError("Expected: a data type name, found: EOF".to_owned()),
bigquery().parse_sql_statements(error_sql).unwrap_err()
);

let error_sql = "DECLARE x 42";
assert_eq!(
ParserError::ParserError("Expected a data type name, found: 42".to_owned()),
ParserError::ParserError("Expected: a data type name, found: 42".to_owned()),
bigquery().parse_sql_statements(error_sql).unwrap_err()
);
}
Expand Down Expand Up @@ -2069,23 +2069,23 @@ fn test_bigquery_create_function() {
"AS ((SELECT 1 FROM mytable)) ",
"OPTIONS(a = [1, 2])",
),
"Expected end of statement, found: OPTIONS",
"Expected: end of statement, found: OPTIONS",
),
(
concat!(
"CREATE TEMPORARY FUNCTION myfunction() ",
"IMMUTABLE ",
"AS ((SELECT 1 FROM mytable)) ",
),
"Expected AS, found: IMMUTABLE",
"Expected: AS, found: IMMUTABLE",
),
(
concat!(
"CREATE TEMPORARY FUNCTION myfunction() ",
"AS \"console.log('hello');\" ",
"LANGUAGE js ",
),
"Expected end of statement, found: LANGUAGE",
"Expected: end of statement, found: LANGUAGE",
),
];
for (sql, error) in error_sqls {
Expand Down Expand Up @@ -2116,7 +2116,7 @@ fn test_bigquery_trim() {
// missing comma separation
let error_sql = "SELECT TRIM('xyz' 'a')";
assert_eq!(
ParserError::ParserError("Expected ), found: 'a'".to_owned()),
ParserError::ParserError("Expected: ), found: 'a'".to_owned()),
bigquery().parse_sql_statements(error_sql).unwrap_err()
);
}
Expand Down
Loading
Loading