MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / render_error

Function render_error

src/sql-parser/src/lib.rs:52–68  ·  view source on GitHub ↗
(sql: &str, e: parser::ParserError)

Source from the content-addressed store, hash-verified

50 use unicode_width::UnicodeWidthStr;
51
52 fn render_error(sql: &str, e: parser::ParserError) -> String {
53 let mut s = format!("error: {}\n", e.message);
54
55 // Do our best to emulate psql in rendering a caret pointing at the
56 // offending character in the query. This makes it possible to detect
57 // incorrect error positions by visually scanning the test files.
58 let end = sql.len();
59 let line_start = sql[..e.pos].rfind('\n').map(|p| p + 1).unwrap_or(0);
60 let line_end = sql[e.pos..].find('\n').map(|p| e.pos + p).unwrap_or(end);
61 writeln!(s, "{}", &sql[line_start..line_end]);
62 for _ in 0..sql[line_start..e.pos].width() {
63 write!(s, " ");
64 }
65 writeln!(s, "^");
66
67 s
68 }
69
70 fn parse_statement(tc: &TestCase) -> String {
71 let input = tc.input.strip_suffix('\n').unwrap_or(&tc.input);

Callers 2

parse_statementFunction · 0.85
parse_scalarFunction · 0.85

Calls 3

lenMethod · 0.45
mapMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected