From c5baf11a2d863555db3a0054cc8f0782f86237bd Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Thu, 19 Jan 2023 14:23:04 -0800 Subject: [PATCH] Show the ninja string that failed to parse in errors So that it's easier to debug what the problem is. Test: m nothing Change-Id: I97e81f98f0365e981d34c6b8bec8528de1b7e514 --- ninja_strings.go | 2 +- ninja_strings_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ninja_strings.go b/ninja_strings.go index 51a167d..0b783c3 100644 --- a/ninja_strings.go +++ b/ninja_strings.go @@ -118,7 +118,7 @@ func parseNinjaString(scope scope, str string) (ninjaString, error) { r := rune(str[i]) state, err = state(parseState, i, r) if err != nil { - return nil, err + return nil, fmt.Errorf("error parsing ninja string %q: %s", str, err) } } diff --git a/ninja_strings_test.go b/ninja_strings_test.go index c1e05f7..f400074 100644 --- a/ninja_strings_test.go +++ b/ninja_strings_test.go @@ -87,7 +87,7 @@ var ninjaParseTestCases = []struct { strs: []string{"$ ", " "}, }, { input: "foo $ bar", - err: "invalid character after '$' at byte offset 5", + err: `error parsing ninja string "foo $ bar": invalid character after '$' at byte offset 5`, }, { input: "foo $", @@ -95,11 +95,11 @@ var ninjaParseTestCases = []struct { }, { input: "foo ${} bar", - err: "empty variable name at byte offset 6", + err: `error parsing ninja string "foo ${} bar": empty variable name at byte offset 6`, }, { input: "foo ${abc!} bar", - err: "invalid character in variable name at byte offset 9", + err: `error parsing ninja string "foo ${abc!} bar": invalid character in variable name at byte offset 9`, }, { input: "foo ${abc",