Skip to content

Commit 2f04475

Browse files
authored
improved error messages (#201)
1 parent 021ab69 commit 2f04475

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

internal/config/local.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,24 @@ func (l *Local) InitLocalProxyConfig() error {
4040

4141
func (l *Local) InitLocalConfig() error {
4242
if err := l.InitLocalProxyConfig(); err != nil {
43+
panic(err)
4344
return err
4445
}
4546

4647
type Tmp struct {
4748
Local *config.Config `json:"local"`
4849
}
4950
localConfig := &Tmp{}
50-
d, e := os.ReadFile(viper.ConfigFileUsed())
51+
configFile := viper.ConfigFileUsed()
52+
if configFile == "" {
53+
return errors.New("config file needed for local configuration, see https://www.signadot.com/docs/getting-started/installation/signadot-cli")
54+
}
55+
d, e := os.ReadFile(configFile)
5156
if e != nil {
52-
return e
57+
return fmt.Errorf("error reading config file %q: %w", configFile, e)
5358
}
5459
if e := yaml.Unmarshal(d, localConfig); e != nil {
55-
return e
60+
return fmt.Errorf("error unmarshalling config file %q: %w", configFile, e)
5661
}
5762
if localConfig.Local == nil {
5863
return fmt.Errorf("no local section in %s", viper.ConfigFileUsed())

internal/config/locald.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (ld *LocalDaemon) InitLocalDaemon() error {
4141
if ld.ConnectInvocationConfigFile != "" {
4242
ciBytes, err = os.ReadFile(ld.ConnectInvocationConfigFile)
4343
if err != nil {
44-
return err
44+
return fmt.Errorf("error reading connect invocation config file %q: %w", ld.ConnectInvocationConfigFile, err)
4545
}
4646
} else {
4747
ciBytes = []byte(os.Getenv("SIGNADOT_LOCAL_CONNECT_INVOCATION_CONFIG"))

internal/utils/system/system.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
func GetSignadotDir() (string, error) {
1818
homeDir, err := os.UserHomeDir()
1919
if err != nil {
20-
return "", err
20+
return "", fmt.Errorf("error getting user home dir: %w", err)
2121
}
2222
return filepath.Join(homeDir, ".signadot"), nil
2323
}
@@ -76,7 +76,10 @@ func OpenBrowser(url string) error {
7676
default: // "linux", "freebsd", "openbsd", "netbsd"
7777
cmd = exec.Command("xdg-open", url)
7878
}
79-
return cmd.Start()
79+
if err := cmd.Start(); err != nil {
80+
return fmt.Errorf("unable to open url %q: %w", url, err)
81+
}
82+
return nil
8083
}
8184

8285
func GetSandboxesDir() (string, error) {

0 commit comments

Comments
 (0)