Change style of reporting errors with line and pos

Signed-off-by: Waldemar Quevedo <wally@synadia.com>
This commit is contained in:
Waldemar Quevedo
2018-10-02 11:50:47 -07:00
parent 181b07ebc1
commit 18a62cdb60
3 changed files with 5 additions and 6 deletions

View File

@@ -394,12 +394,11 @@ func (p *parser) setValue(val interface{}) {
key := p.popKey() key := p.popKey()
if p.pedantic { if p.pedantic {
it := p.popItemKey()
// Change the position to the beginning of the key // Change the position to the beginning of the key
// since more useful when reporting errors. // since more useful when reporting errors.
switch v := val.(type) { switch v := val.(type) {
case *token: case *token:
it := p.popItemKey()
v.item.pos = it.pos v.item.pos = it.pos
v.item.line = it.line v.item.line = it.line
ctx[key] = v ctx[key] = v

View File

@@ -520,7 +520,7 @@ func TestConfigCheck(t *testing.T) {
err := checkConfig(conf, true) err := checkConfig(conf, true)
expectedErr := test.pedanticErr expectedErr := test.pedanticErr
if err != nil && expectedErr != nil { if err != nil && expectedErr != nil {
msg := fmt.Sprintf("%s in %s:%d:%d", expectedErr.Error(), conf, test.errorLine, test.errorPos) msg := fmt.Sprintf("%s:%d:%d: %s", conf, test.errorLine, test.errorPos, expectedErr.Error())
if test.reason != "" { if test.reason != "" {
msg += ": " + test.reason msg += ": " + test.reason
} }
@@ -560,7 +560,7 @@ func TestConfigCheckIncludes(t *testing.T) {
if err == nil { if err == nil {
t.Errorf("Expected error processing include files with configuration check enabled: %v", err) t.Errorf("Expected error processing include files with configuration check enabled: %v", err)
} }
expectedErr := errors.New(`unknown field "monitoring_port" in configs/include_bad_conf_check_b.conf:10:19`) expectedErr := errors.New(`configs/include_bad_conf_check_b.conf:10:19: unknown field "monitoring_port"`)
if err != nil && expectedErr != nil && err.Error() != expectedErr.Error() { if err != nil && expectedErr != nil && err.Error() != expectedErr.Error() {
t.Errorf("Expected %q, got %q", expectedErr.Error(), err.Error()) t.Errorf("Expected %q, got %q", expectedErr.Error(), err.Error())
} }

View File

@@ -208,7 +208,7 @@ type unknownConfigFieldErr struct {
func (e *unknownConfigFieldErr) Error() string { func (e *unknownConfigFieldErr) Error() string {
msg := fmt.Sprintf("unknown field %q", e.field) msg := fmt.Sprintf("unknown field %q", e.field)
if e.token != nil { if e.token != nil {
return msg + fmt.Sprintf(" in %s:%d:%d", e.configFile, e.token.Line(), e.token.Position()) return fmt.Sprintf("%s:%d:%d: %s", e.configFile, e.token.Line(), e.token.Position(), msg)
} }
return msg return msg
} }
@@ -223,7 +223,7 @@ type configWarningErr struct {
func (e *configWarningErr) Error() string { func (e *configWarningErr) Error() string {
msg := fmt.Sprintf("invalid use of field %q", e.field) msg := fmt.Sprintf("invalid use of field %q", e.field)
if e.token != nil { if e.token != nil {
msg += fmt.Sprintf(" in %s:%d:%d", e.configFile, e.token.Line(), e.token.Position()) msg = fmt.Sprintf("%s:%d:%d: %s", e.configFile, e.token.Line(), e.token.Position(), msg)
} }
msg += ": " + e.reason msg += ": " + e.reason
return msg return msg