From 7af17baa8a13337db14872909769d14327a42d3c Mon Sep 17 00:00:00 2001 From: bui Date: Thu, 7 Oct 2021 18:36:05 +0200 Subject: [PATCH] up better errorz --- cmd/crowdsec-cli/console.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/crowdsec-cli/console.go b/cmd/crowdsec-cli/console.go index 776569786..67333186d 100644 --- a/cmd/crowdsec-cli/console.go +++ b/cmd/crowdsec-cli/console.go @@ -3,7 +3,9 @@ package main import ( "context" "encoding/json" + "errors" "fmt" + "io/fs" "net/url" "github.com/crowdsecurity/crowdsec/pkg/apiclient" @@ -24,7 +26,16 @@ func NewConsoleCmd() *cobra.Command { Args: cobra.MinimumNArgs(1), DisableAutoGenTag: true, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI { + if err := csConfig.LoadAPIServer(); err != nil { + var fdErr *fs.PathError + if errors.As(err, &fdErr) { + log.Fatalf("Unable to load Local API : %s", fdErr) + } else { + log.Fatalf("Unable to load required Local API Configuration : %s", err) + } + } + + if csConfig.DisableAPI { log.Fatal("Local API is disabled, please run this command on the local API machine") } if csConfig.API.Server.OnlineClient == nil {