mirror of
https://codeberg.org/scip/anydb.git
synced 2025-12-17 12:31:02 +01:00
better error handling
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
func WriteFile(attr *app.DbAttr, conf *cfg.Config, entries app.DbEntries) error {
|
||||
jsonentries, err := json.Marshal(entries)
|
||||
if err != nil {
|
||||
return fmt.Errorf("json marshalling failure: %s", err)
|
||||
return fmt.Errorf("failed to marshall json: %w", err)
|
||||
}
|
||||
|
||||
if attr.File == "-" {
|
||||
@@ -20,11 +20,11 @@ func WriteFile(attr *app.DbAttr, conf *cfg.Config, entries app.DbEntries) error
|
||||
} else {
|
||||
fd, err := os.OpenFile(attr.File, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to open file %s for writing: %w", attr.File, err)
|
||||
}
|
||||
|
||||
if _, err := fd.Write(jsonentries); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed writing to file %s: %w", attr.File, err)
|
||||
}
|
||||
|
||||
fmt.Printf("database contents exported to %s\n", attr.File)
|
||||
|
||||
Reference in New Issue
Block a user