Skip to content

Commit 00f780a

Browse files
committed
Make flags file format errors easier to understand.
Fix json tests.
1 parent e2df3fa commit 00f780a

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

file.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func (f *Flags) Set(value string, opt getopt.Option) error {
203203
// we can re-play after the subset is registered.
204204
m, err := f.Decoder(data)
205205
if err != nil {
206-
return err
206+
return fmt.Errorf("%s: %v", value, err)
207207
}
208208
f.m = mergemap(f.m, m)
209209
}

json/json.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Paul Borman
1+
// Copyright 2019 Paul Borman
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ package json
3131
import (
3232
"bytes"
3333
"encoding/json"
34+
"fmt"
3435

3536
"github.com/pborman/options"
3637
)
@@ -45,7 +46,7 @@ func Decoder(data []byte) (map[string]interface{}, error) {
4546
m := map[string]interface{}{}
4647
for decoder.More() {
4748
if err := decoder.Decode(&m); err != nil {
48-
return nil, err
49+
return nil, fmt.Errorf("JSON decoding error: %v", err)
4950
}
5051
}
5152
return m, nil

json/json_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55
"fmt"
66
"io/ioutil"
77
"os"
8-
"pkg/prb/uuid"
98
"reflect"
109
"testing"
1110

11+
"github.com/google/uuid"
1212
getopt "github.com/pborman/getopt/v2"
1313
"github.com/pborman/options"
1414
)

0 commit comments

Comments
 (0)