aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-08-01 17:26:27 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-08-01 17:26:27 +0100
commit018beb15661ff80a5a79759a21f69d590344b9c4 (patch)
tree2ea1afa7e4382289f081f19057502ac806f97865
parentf6bdd83dc22834f5c0134aabeb75f4ac23fbdf63 (diff)
better error handling
-rw-r--r--pkg/datamaps/writer.go14
1 files changed, 9 insertions, 5 deletions
diff --git a/pkg/datamaps/writer.go b/pkg/datamaps/writer.go
index 48599e6..e820049 100644
--- a/pkg/datamaps/writer.go
+++ b/pkg/datamaps/writer.go
@@ -2,6 +2,7 @@ package datamaps
import (
"database/sql"
+ "fmt"
"log"
"path/filepath"
@@ -109,7 +110,10 @@ func ExportMaster(opts *Options) error {
if err := masterData.Scan(&key, &value, &filename); err != nil {
return err
}
- values = appendValueMap(key, value, values)
+ values, err = appendValueMap(key, value, values)
+ if err != nil {
+ return err
+ }
}
}
}
@@ -134,7 +138,7 @@ func ExportMaster(opts *Options) error {
return nil
}
-func appendValueMap(k, v string, values map[string][]string) map[string][]string {
+func appendValueMap(k, v string, values map[string][]string) (map[string][]string, error) {
var keyIn bool
for kv, _ := range values {
@@ -147,13 +151,13 @@ func appendValueMap(k, v string, values map[string][]string) map[string][]string
if keyIn {
slice, ok := values[k]
if !ok {
- log.Fatalf("%s is not a key in this map", k)
+ return nil, fmt.Errorf("%s is not a key in this map", k)
}
slice = append(slice, v)
values[k] = slice
- return values
+ return values, nil
} else {
values[k] = []string{v}
- return values
+ return values, nil
}
}