mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Change style of reporting errors with line and pos
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
This commit is contained in:
@@ -394,12 +394,11 @@ func (p *parser) setValue(val interface{}) {
|
||||
key := p.popKey()
|
||||
|
||||
if p.pedantic {
|
||||
it := p.popItemKey()
|
||||
|
||||
// Change the position to the beginning of the key
|
||||
// since more useful when reporting errors.
|
||||
switch v := val.(type) {
|
||||
case *token:
|
||||
it := p.popItemKey()
|
||||
v.item.pos = it.pos
|
||||
v.item.line = it.line
|
||||
ctx[key] = v
|
||||
|
||||
@@ -520,7 +520,7 @@ func TestConfigCheck(t *testing.T) {
|
||||
err := checkConfig(conf, true)
|
||||
expectedErr := test.pedanticErr
|
||||
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 != "" {
|
||||
msg += ": " + test.reason
|
||||
}
|
||||
@@ -560,7 +560,7 @@ func TestConfigCheckIncludes(t *testing.T) {
|
||||
if err == nil {
|
||||
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() {
|
||||
t.Errorf("Expected %q, got %q", expectedErr.Error(), err.Error())
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ type unknownConfigFieldErr struct {
|
||||
func (e *unknownConfigFieldErr) Error() string {
|
||||
msg := fmt.Sprintf("unknown field %q", e.field)
|
||||
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
|
||||
}
|
||||
@@ -223,7 +223,7 @@ type configWarningErr struct {
|
||||
func (e *configWarningErr) Error() string {
|
||||
msg := fmt.Sprintf("invalid use of field %q", e.field)
|
||||
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
|
||||
return msg
|
||||
|
||||
Reference in New Issue
Block a user