client config: use JSON errorutil.HighlightBytePosition helper

This commit is contained in:
Brad Fitzpatrick 2011-05-15 21:56:17 -07:00
parent 5cf560c600
commit bbf3408920
1 changed files with 13 additions and 1 deletions

View File

@ -18,6 +18,7 @@ package client
import (
"flag"
"fmt"
"json"
"log"
"os"
@ -27,6 +28,7 @@ import (
"syscall"
"camli/blobref"
"camli/errorutil"
"camli/osutil"
)
@ -55,7 +57,17 @@ func parseConfig() {
defer f.Close()
dj := json.NewDecoder(f)
if err := dj.Decode(&config); err != nil {
log.Printf("Error parsing JSON in config file %q: %v", ConfigFilePath(), err)
extra := ""
if serr, ok := err.(*json.SyntaxError); ok {
if _, serr := f.Seek(0, os.SEEK_SET); serr != nil {
log.Fatalf("seek error: %v", serr)
}
line, col, highlight := errorutil.HighlightBytePosition(f, serr.Offset)
extra = fmt.Sprintf(":\nError at line %d, column %d (file offset %d):\n%s",
line, col, serr.Offset, highlight)
}
log.Printf("error parsing JSON object in config file %s%s\n%v",
ConfigFilePath(), extra, err)
}
}
}