Skip to content
Snippets Groups Projects
Commit 572cbd1f authored by Kieran Trezona-le Comte's avatar Kieran Trezona-le Comte
Browse files

Truncate long "at or near ..." error messages

parent 5d5761b5
No related branches found
No related tags found
No related merge requests found
...@@ -6,4 +6,4 @@ ...@@ -6,4 +6,4 @@
- [ ] Support for other SQL dialects - [ ] Support for other SQL dialects
- [ ] JSON output - [ ] JSON output
- [ ] Huge files - [ ] Huge files
- [ ] Maybe truncate long 'at or near "blah"' strings - [X] Maybe truncate long 'at or near "blah"' strings
...@@ -31,7 +31,7 @@ module SQLint ...@@ -31,7 +31,7 @@ module SQLint
rescue PgQuery::ParseError => e rescue PgQuery::ParseError => e
offset = e.location + parse_state.offset offset = e.location + parse_state.offset
line_number, column_number = find_absolute_position(offset) line_number, column_number = find_absolute_position(offset)
lint = Lint.new(@filename, line_number, column_number, :error, e.message) lint = Lint.new(@filename, line_number, column_number, :error, clean_message(e.message))
input_from_error = parse_state.input[e.location..-1] input_from_error = parse_state.input[e.location..-1]
semicolon_pos = input_from_error.index(";") if input_from_error semicolon_pos = input_from_error.index(";") if input_from_error
...@@ -54,5 +54,9 @@ module SQLint ...@@ -54,5 +54,9 @@ module SQLint
column_number = lines_before_error.any? ? lines_before_error.last.size : 1 column_number = lines_before_error.any? ? lines_before_error.last.size : 1
[line_number, column_number] [line_number, column_number]
end end
def clean_message(message)
message.gsub(/(?<=at or near ")(.*)(?=")/) { |match| match[0..49] }
end
end end
end end
...@@ -69,10 +69,19 @@ RSpec.describe SQLint::Linter do ...@@ -69,10 +69,19 @@ RSpec.describe SQLint::Linter do
context "when there is a second error at the end of the file" do context "when there is a second error at the end of the file" do
let(:input) { "WIBBLE; SELECT 1 FROM" } let(:input) { "WIBBLE; SELECT 1 FROM" }
it "report 2 errors" do it "reports 2 errors" do
expect(results).to eq([error(1, 1, WIBBLE_ERROR), expect(results).to eq([error(1, 1, WIBBLE_ERROR),
error(1, 21, "syntax error at end of input")]) error(1, 21, "syntax error at end of input")])
end end
end end
end end
describe "long error messages" do
context "when the 'at or near' fragment is longer than 50 characters" do
let(:input) { "SELECT '" + 'x' * 100 }
it "truncates the fragment" do
expect(results).to eq([error(1, 8, "unterminated quoted string at or near \"'#{'x' * 49}\"")])
end
end
end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment