Skip to content

Commit

Permalink
Use features of BurntSushi/toml v1.0.0
Browse files Browse the repository at this point in the history
Especially the new error description should be helpful
  • Loading branch information
Top-Ranger committed Mar 15, 2022
1 parent 5b2ed6b commit 14e6703
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion configuration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"os"

Expand All @@ -21,7 +22,11 @@ func (c *configuration) readFile(fp string) error {
}
defer cf.Close()

if _, err := toml.DecodeReader(cf, &c); err != nil {
if _, err := toml.NewDecoder(cf).Decode(&c); err != nil {
var terr toml.ParseError
if errors.As(err, &terr) {
return fmt.Errorf("failed to decode configuration file: %s", terr.ErrorWithUsage())
}
return fmt.Errorf("failed to decode configuration file: %w", err)
}

Expand Down

0 comments on commit 14e6703

Please sign in to comment.