From 48f614beda9c0614ef4760dea7d4d17a460d9636 Mon Sep 17 00:00:00 2001 From: Lukasz Mierzwa Date: Thu, 14 Oct 2021 11:59:10 +0100 Subject: [PATCH] Fix off-by-one error in line reporting When a file fails to parse we try to extract line number from YAML error, there's bogus +1 there. --- cmd/pint/scan.go | 2 +- cmd/pint/tests/0004_fail_invalid_yaml.txt | 4 ++-- cmd/pint/tests/0010_syntax_check.txt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/pint/scan.go b/cmd/pint/scan.go index a6559a49..483eb59a 100644 --- a/cmd/pint/scan.go +++ b/cmd/pint/scan.go @@ -27,7 +27,7 @@ func tryDecodingYamlError(e string) (int, string) { if err != nil { return 1, e } - return line + 1, parts[2] + return line, parts[2] } return 1, e } diff --git a/cmd/pint/tests/0004_fail_invalid_yaml.txt b/cmd/pint/tests/0004_fail_invalid_yaml.txt index 2dbc0795..ef607b52 100644 --- a/cmd/pint/tests/0004_fail_invalid_yaml.txt +++ b/cmd/pint/tests/0004_fail_invalid_yaml.txt @@ -5,8 +5,8 @@ cmp stderr stderr.txt -- stderr.txt -- level=error msg="Failed to parse file content" error="yaml: line 4: did not find expected key" path=rules/bad.yaml level=info msg="File parsed" path=rules/ok.yml rules=1 -rules/bad.yaml:5: did not find expected key (pint/parse) -- xx +rules/bad.yaml:4: did not find expected key (pint/parse) + rules/ok.yml:2: syntax error: unclosed left bracket (promql/syntax) expr: sum(foo[5m) diff --git a/cmd/pint/tests/0010_syntax_check.txt b/cmd/pint/tests/0010_syntax_check.txt index 5306bda3..4a93219e 100644 --- a/cmd/pint/tests/0010_syntax_check.txt +++ b/cmd/pint/tests/0010_syntax_check.txt @@ -4,8 +4,8 @@ cmp stderr stderr.txt -- stderr.txt -- level=error msg="Failed to parse file content" error="yaml: line 6: did not find expected '-' indicator" path=rules/1.yaml -rules/1.yaml:7: did not find expected '-' indicator (pint/parse) -alert: Bad +rules/1.yaml:6: did not find expected '-' indicator (pint/parse) + level=info msg="Problems found" Fatal=1 level=fatal msg="Fatal error" error="problems found"