Skip to content

Commit f16c1af

Browse files
Improve error messages with additional colons (#1319)
1 parent 79af31b commit f16c1af

11 files changed

+144
-144
lines changed

src/parser/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3116,7 +3116,7 @@ impl<'a> Parser<'a> {
31163116
/// Report `found` was encountered instead of `expected`
31173117
pub fn expected<T>(&self, expected: &str, found: TokenWithLocation) -> Result<T, ParserError> {
31183118
parser_err!(
3119-
format!("Expected {expected}, found: {found}"),
3119+
format!("Expected: {expected}, found: {found}"),
31203120
found.location
31213121
)
31223122
}
@@ -11581,7 +11581,7 @@ mod tests {
1158111581
assert_eq!(
1158211582
ast,
1158311583
Err(ParserError::TokenizerError(
11584-
"Unterminated string literal at Line: 1, Column 5".to_string()
11584+
"Unterminated string literal at Line: 1, Column: 5".to_string()
1158511585
))
1158611586
);
1158711587
}
@@ -11593,7 +11593,7 @@ mod tests {
1159311593
assert_eq!(
1159411594
ast,
1159511595
Err(ParserError::ParserError(
11596-
"Expected [NOT] NULL or TRUE|FALSE or [NOT] DISTINCT FROM after IS, found: a at Line: 1, Column 16"
11596+
"Expected: [NOT] NULL or TRUE|FALSE or [NOT] DISTINCT FROM after IS, found: a at Line: 1, Column: 16"
1159711597
.to_string()
1159811598
))
1159911599
);

src/tokenizer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl fmt::Display for Location {
429429
write!(
430430
f,
431431
// TODO: use standard compiler location syntax (<path>:<line>:<col>)
432-
" at Line: {}, Column {}",
432+
" at Line: {}, Column: {}",
433433
self.line, self.column,
434434
)
435435
}
@@ -1816,7 +1816,7 @@ mod tests {
18161816
use std::error::Error;
18171817
assert!(err.source().is_none());
18181818
}
1819-
assert_eq!(err.to_string(), "test at Line: 1, Column 1");
1819+
assert_eq!(err.to_string(), "test at Line: 1, Column: 1");
18201820
}
18211821

18221822
#[test]

tests/sqlparser_bigquery.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ fn parse_invalid_brackets() {
535535
bigquery_and_generic()
536536
.parse_sql_statements(sql)
537537
.unwrap_err(),
538-
ParserError::ParserError("Expected (, found: >".to_string())
538+
ParserError::ParserError("Expected: (, found: >".to_string())
539539
);
540540

541541
let sql = "CREATE TABLE table (x STRUCT<STRUCT<INT64>>>)";
@@ -544,7 +544,7 @@ fn parse_invalid_brackets() {
544544
.parse_sql_statements(sql)
545545
.unwrap_err(),
546546
ParserError::ParserError(
547-
"Expected ',' or ')' after column definition, found: >".to_string()
547+
"Expected: ',' or ')' after column definition, found: >".to_string()
548548
)
549549
);
550550
}
@@ -1753,11 +1753,11 @@ fn parse_merge_invalid_statements() {
17531753
for (sql, err_msg) in [
17541754
(
17551755
"MERGE T USING U ON TRUE WHEN MATCHED BY TARGET AND 1 THEN DELETE",
1756-
"Expected THEN, found: BY",
1756+
"Expected: THEN, found: BY",
17571757
),
17581758
(
17591759
"MERGE T USING U ON TRUE WHEN MATCHED BY SOURCE AND 1 THEN DELETE",
1760-
"Expected THEN, found: BY",
1760+
"Expected: THEN, found: BY",
17611761
),
17621762
(
17631763
"MERGE T USING U ON TRUE WHEN NOT MATCHED BY SOURCE THEN INSERT(a) VALUES (b)",
@@ -1898,13 +1898,13 @@ fn parse_big_query_declare() {
18981898

18991899
let error_sql = "DECLARE x";
19001900
assert_eq!(
1901-
ParserError::ParserError("Expected a data type name, found: EOF".to_owned()),
1901+
ParserError::ParserError("Expected: a data type name, found: EOF".to_owned()),
19021902
bigquery().parse_sql_statements(error_sql).unwrap_err()
19031903
);
19041904

19051905
let error_sql = "DECLARE x 42";
19061906
assert_eq!(
1907-
ParserError::ParserError("Expected a data type name, found: 42".to_owned()),
1907+
ParserError::ParserError("Expected: a data type name, found: 42".to_owned()),
19081908
bigquery().parse_sql_statements(error_sql).unwrap_err()
19091909
);
19101910
}
@@ -2069,23 +2069,23 @@ fn test_bigquery_create_function() {
20692069
"AS ((SELECT 1 FROM mytable)) ",
20702070
"OPTIONS(a = [1, 2])",
20712071
),
2072-
"Expected end of statement, found: OPTIONS",
2072+
"Expected: end of statement, found: OPTIONS",
20732073
),
20742074
(
20752075
concat!(
20762076
"CREATE TEMPORARY FUNCTION myfunction() ",
20772077
"IMMUTABLE ",
20782078
"AS ((SELECT 1 FROM mytable)) ",
20792079
),
2080-
"Expected AS, found: IMMUTABLE",
2080+
"Expected: AS, found: IMMUTABLE",
20812081
),
20822082
(
20832083
concat!(
20842084
"CREATE TEMPORARY FUNCTION myfunction() ",
20852085
"AS \"console.log('hello');\" ",
20862086
"LANGUAGE js ",
20872087
),
2088-
"Expected end of statement, found: LANGUAGE",
2088+
"Expected: end of statement, found: LANGUAGE",
20892089
),
20902090
];
20912091
for (sql, error) in error_sqls {
@@ -2116,7 +2116,7 @@ fn test_bigquery_trim() {
21162116
// missing comma separation
21172117
let error_sql = "SELECT TRIM('xyz' 'a')";
21182118
assert_eq!(
2119-
ParserError::ParserError("Expected ), found: 'a'".to_owned()),
2119+
ParserError::ParserError("Expected: ), found: 'a'".to_owned()),
21202120
bigquery().parse_sql_statements(error_sql).unwrap_err()
21212121
);
21222122
}

0 commit comments

Comments
 (0)