diff --git a/client/client.go b/client/client.go index 471828095..b97c654ab 100644 --- a/client/client.go +++ b/client/client.go @@ -40,6 +40,9 @@ func (c *Client) Run(query string) (string, error) { c.logger.Debug("Querying %s with:\n\n%s\n\n", c.endpoint, query) err := c.client.Run(ctx, req, &resp) + if err != nil { + return "", err + } b, err := json.MarshalIndent(resp, "", " ") if err != nil { diff --git a/cmd/query.go b/cmd/query.go index e93c4412d..d4d5634d0 100644 --- a/cmd/query.go +++ b/cmd/query.go @@ -28,5 +28,5 @@ func query(cmd *cobra.Command, args []string) { Logger.FatalOnError("Error occurred when running query", err) } - Logger.Infoln(string(resp)) + Logger.Infoln(resp) } diff --git a/config/config.go b/config/config.go index 99647f798..fa58e3343 100644 --- a/config/config.go +++ b/config/config.go @@ -1,13 +1,13 @@ package config import ( - "errors" "fmt" "os" "github.com/spf13/viper" ) +// Config is a struct of the current configuration available at runtime. type Config struct { Verbose bool File string @@ -30,10 +30,8 @@ func (c *Config) Init() error { c.File = c.DefaultPath // reload after creating config - if err := c.read(); err != nil { - return err - } - return nil + err := c.read() + return err } // read tries to load the config either from Config.defaultPath or Config.file. @@ -68,10 +66,10 @@ func (c *Config) create() error { if _, err := os.Stat(path); os.IsNotExist(err) { if err = os.Mkdir(path, 0700); err != nil { - return errors.New(fmt.Sprintf("Error creating directory: '%s'", path)) + return fmt.Errorf("Error creating directory: '%s'", path) } } else { - return errors.New(fmt.Sprintf("Error accessing directory: '%s'", path)) + return fmt.Errorf("Error accessing directory: '%s'", path) } // Create default config file @@ -85,7 +83,10 @@ func (c *Config) create() error { return err } defer func() { - file.Close() + cerr := file.Close() + if err == nil { + err = cerr + } }() // read flag values @@ -94,7 +95,9 @@ func (c *Config) create() error { if token == "token" || token == "" { fmt.Print("Please enter your CircleCI API token: ") - fmt.Scanln(&token) + if _, err = fmt.Scanln(&token); err != nil { + return err + } fmt.Println("OK.") }