Created
January 8, 2014 10:14
-
-
Save simonschmidt/8314577 to your computer and use it in GitHub Desktop.
More descriptive error for json2csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/main.go b/main.go | |
index f4407a6..c430412 100644 | |
--- a/main.go | |
+++ b/main.go | |
@@ -96,6 +96,7 @@ func get_value(data map[string]interface{}, keyparts []string) string { | |
func json2csv(r LineReader, w *csv.Writer, keys []string, printHeader bool) { | |
var line []byte | |
var err error | |
+ line_count := 0 | |
var expanded_keys [][]string | |
for _, key := range keys { | |
@@ -113,6 +114,7 @@ func json2csv(r LineReader, w *csv.Writer, keys []string, printHeader bool) { | |
break | |
} | |
} | |
+ line_count++ | |
if len(line) == 0 { | |
continue | |
} | |
@@ -126,7 +128,7 @@ func json2csv(r LineReader, w *csv.Writer, keys []string, printHeader bool) { | |
var data map[string]interface{} | |
err = json.Unmarshal(line, &data) | |
if err != nil { | |
- log.Printf("ERROR Json Decoding: %s - %v", err, line) | |
+ log.Printf("ERROR Decoding JSON at line %d: %s\n%s", line_count, err, line) | |
continue | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment