Skip to content

Commit 12b58c6

Browse files
private/app/launcher: unwrap errors fully to avoid hiding cause
As an example, before this commit, when a key was removed from the struct that defines available configuration option for the toml file for a given application such as the scion-dispatcher, it would fail without reporting what key is present when it should be removed from the config file, as follows: error: loading config from file {file=/foo.toml}: strict mode: fields in the document are missing in the target struct After this commit it will fail more informatively as follows: error: loading config from file {file=/foo.toml}: strict mode: fields in the document are missing in the target struct &toml.StrictMissingError{Errors:[]t oml.DecodeError{toml.DecodeError{message:"missing field", line:4, column:1, key:toml.Key{"general", "reconnect_to_dispatcher"}, human:"1| [general]\n2| config_dir = \"/etc/scion\"\n3| id = \"sd\"\n4| reconnect_to_dispatcher = true\n | ~~~~~~~~~~~~~~~~~~~~~ ~~ missing field\n5|\n6| [log.console]\n7| level = \"info\""}}} You can see the reason for the failure is the presence of the "reconnect_to_dispatcher" key, which no longer exists
1 parent 4ab4513 commit 12b58c6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

private/app/launcher/launcher_unix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"path/filepath"
2424
"syscall"
2525
"time"
26+
"errors"
2627

2728
"github.com/spf13/cobra"
2829
"github.com/spf13/viper"
@@ -46,7 +47,7 @@ type Application struct {
4647
// Run will exit the application if it encounters a fatal error.
4748
func (a *Application) Run() {
4849
if err := a.run(); err != nil {
49-
fmt.Fprintf(a.getErrorWriter(), "fatal error: %v\n", err)
50+
fmt.Fprintf(a.getErrorWriter(), "fatal error: %v\n %#v\n", err, errors.Unwrap(err))
5051
os.Exit(1)
5152
}
5253
}

private/app/launcher/launcher_windows.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"path/filepath"
2525
"syscall"
2626
"time"
27+
"errors"
2728

2829
"github.com/spf13/cobra"
2930
"github.com/spf13/viper"
@@ -73,7 +74,7 @@ type Application struct {
7374
// Run will exit the application if it encounters a fatal error.
7475
func (a *Application) Run() {
7576
if ec, err := a.run(); err != nil {
76-
fmt.Fprintf(a.getErrorWriter(), "fatal error: %v\n", err)
77+
fmt.Fprintf(a.getErrorWriter(), "fatal error: %v\n %#v\n", err, errors.Unwrap(err))
7778
os.Exit(ec)
7879
}
7980
}

0 commit comments

Comments
 (0)