Improve error messages (#6014)
This commit is contained in:
parent
3324a0f1a7
commit
7a307c356a
2 changed files with 26 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ package cmd
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
|
@ -99,3 +100,24 @@ func shutdownDoneC() <-chan struct{} {
|
|||
go shutdown.Cleanup(doneC)
|
||||
return doneC
|
||||
}
|
||||
|
||||
func wrapErrors(err error) error {
|
||||
if err != nil {
|
||||
var opErr *net.OpError
|
||||
var pathErr *os.PathError
|
||||
|
||||
switch {
|
||||
case errors.As(err, &opErr):
|
||||
if opErr.Op == "listen" && strings.Contains(opErr.Error(), "address already in use") {
|
||||
err = fmt.Errorf("could not open port- check that evcc is not already running (%w)", err)
|
||||
}
|
||||
|
||||
case errors.As(err, &pathErr):
|
||||
if pathErr.Op == "remove" && strings.Contains(pathErr.Error(), "operation not permitted") {
|
||||
err = fmt.Errorf("could not remove file- check that evcc is not already running (%w)", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -268,6 +268,9 @@ func runRoot(cmd *cobra.Command, args []string) {
|
|||
once.Do(func() { close(stopC) }) // signal loop to end
|
||||
})
|
||||
|
||||
// improve error message
|
||||
err = wrapErrors(err)
|
||||
|
||||
publishErrorInfo(valueChan, cfgFile, err)
|
||||
|
||||
log.FATAL.Println(err)
|
||||
|
|
@ -282,5 +285,5 @@ func runRoot(cmd *cobra.Command, args []string) {
|
|||
// uds health check listener
|
||||
go server.HealthListener(site)
|
||||
|
||||
log.FATAL.Println(httpd.ListenAndServe())
|
||||
log.FATAL.Println(wrapErrors(httpd.ListenAndServe()))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue