Switch to fmt.Errorf
Replace all instances of errors.Wrap() with fmt.Errorf. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
10dcbec954
commit
118319c7c1
88 changed files with 1007 additions and 4467 deletions
|
|
@ -21,7 +21,6 @@ import (
|
|||
|
||||
openapiRuntimeClient "github.com/go-openapi/runtime/client"
|
||||
"github.com/jedib0t/go-pretty/v6/table"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
apiClientController "github.com/cloudbase/garm/client/controller"
|
||||
|
|
@ -80,7 +79,7 @@ garm-cli init --name=dev --url=https://runner.example.com --username=admin --pas
|
|||
|
||||
response, err := apiCli.FirstRun.FirstRun(newUserReq, authToken)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "initializing manager")
|
||||
return fmt.Errorf("error initializing manager: %w", err)
|
||||
}
|
||||
|
||||
newLoginParamsReq := apiClientLogin.NewLoginParams()
|
||||
|
|
@ -91,7 +90,7 @@ garm-cli init --name=dev --url=https://runner.example.com --username=admin --pas
|
|||
|
||||
token, err := apiCli.Login.Login(newLoginParamsReq, authToken)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "authenticating")
|
||||
return fmt.Errorf("error authenticating: %w", err)
|
||||
}
|
||||
|
||||
cfg.Managers = append(cfg.Managers, config.Manager{
|
||||
|
|
@ -104,7 +103,7 @@ garm-cli init --name=dev --url=https://runner.example.com --username=admin --pas
|
|||
cfg.ActiveManager = loginProfileName
|
||||
|
||||
if err := cfg.SaveConfig(); err != nil {
|
||||
return errors.Wrap(err, "saving config")
|
||||
return fmt.Errorf("error saving config: %w", err)
|
||||
}
|
||||
|
||||
updateUrlsReq := apiClientController.NewUpdateControllerParams()
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/jedib0t/go-pretty/v6/table"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
commonParams "github.com/cloudbase/garm-provider-common/params"
|
||||
|
|
@ -471,7 +470,7 @@ func init() {
|
|||
func extraSpecsFromFile(specsFile string) (json.RawMessage, error) {
|
||||
data, err := os.ReadFile(specsFile)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "opening specs file")
|
||||
return nil, fmt.Errorf("error opening specs file: %w", err)
|
||||
}
|
||||
return asRawMessage(data)
|
||||
}
|
||||
|
|
@ -481,14 +480,14 @@ func asRawMessage(data []byte) (json.RawMessage, error) {
|
|||
// have a valid json.
|
||||
var unmarshaled interface{}
|
||||
if err := json.Unmarshal(data, &unmarshaled); err != nil {
|
||||
return nil, errors.Wrap(err, "decoding extra specs")
|
||||
return nil, fmt.Errorf("error decoding extra specs: %w", err)
|
||||
}
|
||||
|
||||
var asRawJSON json.RawMessage
|
||||
var err error
|
||||
asRawJSON, err = json.Marshal(unmarshaled)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "marshaling json")
|
||||
return nil, fmt.Errorf("error marshaling json: %w", err)
|
||||
}
|
||||
return asRawJSON, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
runnerErrors "github.com/cloudbase/garm-provider-common/errors"
|
||||
)
|
||||
|
|
@ -34,11 +34,11 @@ const (
|
|||
func getConfigFilePath() (string, error) {
|
||||
configDir, err := getHomeDir()
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "fetching home folder")
|
||||
return "", fmt.Errorf("error fetching home folder: %w", err)
|
||||
}
|
||||
|
||||
if err := ensureHomeDir(configDir); err != nil {
|
||||
return "", errors.Wrap(err, "ensuring config dir")
|
||||
return "", fmt.Errorf("error ensuring config dir: %w", err)
|
||||
}
|
||||
|
||||
cfgFile := filepath.Join(configDir, DefaultConfigFileName)
|
||||
|
|
@ -48,7 +48,7 @@ func getConfigFilePath() (string, error) {
|
|||
func LoadConfig() (*Config, error) {
|
||||
cfgFile, err := getConfigFilePath()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "fetching config")
|
||||
return nil, fmt.Errorf("error fetching config: %w", err)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(cfgFile); err != nil {
|
||||
|
|
@ -56,12 +56,12 @@ func LoadConfig() (*Config, error) {
|
|||
// return empty config
|
||||
return &Config{}, nil
|
||||
}
|
||||
return nil, errors.Wrap(err, "accessing config file")
|
||||
return nil, fmt.Errorf("error accessing config file: %w", err)
|
||||
}
|
||||
|
||||
var config Config
|
||||
if _, err := toml.DecodeFile(cfgFile, &config); err != nil {
|
||||
return nil, errors.Wrap(err, "decoding toml")
|
||||
return nil, fmt.Errorf("error decoding toml: %w", err)
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
|
|
@ -157,17 +157,17 @@ func (c *Config) SaveConfig() error {
|
|||
cfgFile, err := getConfigFilePath()
|
||||
if err != nil {
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
return errors.Wrap(err, "getting config")
|
||||
return fmt.Errorf("error getting config: %w", err)
|
||||
}
|
||||
}
|
||||
cfgHandle, err := os.Create(cfgFile)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getting file handle")
|
||||
return fmt.Errorf("error getting file handle: %w", err)
|
||||
}
|
||||
|
||||
encoder := toml.NewEncoder(cfgHandle)
|
||||
if err := encoder.Encode(c); err != nil {
|
||||
return errors.Wrap(err, "saving config")
|
||||
return fmt.Errorf("error saving config: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -15,19 +15,19 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func ensureHomeDir(folder string) error {
|
||||
if _, err := os.Stat(folder); err != nil {
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
return errors.Wrap(err, "checking home dir")
|
||||
return fmt.Errorf("error checking home dir: %w", err)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(folder, 0o710); err != nil {
|
||||
return errors.Wrapf(err, "creating %s", folder)
|
||||
return fmt.Errorf("error creating %s: %w", folder, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,16 +17,15 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func getHomeDir() (string, error) {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "fetching home dir")
|
||||
return "", fmt.Errorf("error fetching home dir: %w", err)
|
||||
}
|
||||
|
||||
return filepath.Join(home, ".local", "share", DefaultAppFolder), nil
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ import (
|
|||
|
||||
"github.com/gorilla/handlers"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/pkg/errors"
|
||||
lumberjack "gopkg.in/natefinch/lumberjack.v2"
|
||||
|
||||
"github.com/cloudbase/garm-provider-common/util"
|
||||
|
|
@ -73,7 +72,7 @@ func maybeInitController(db common.Store) (params.ControllerInfo, error) {
|
|||
|
||||
info, err := db.InitController()
|
||||
if err != nil {
|
||||
return params.ControllerInfo{}, errors.Wrap(err, "initializing controller")
|
||||
return params.ControllerInfo{}, fmt.Errorf("error initializing controller: %w", err)
|
||||
}
|
||||
|
||||
return info, nil
|
||||
|
|
@ -152,7 +151,7 @@ func setupLogging(ctx context.Context, logCfg config.Logging, hub *websocket.Hub
|
|||
func maybeUpdateURLsFromConfig(cfg config.Config, store common.Store) error {
|
||||
info, err := store.ControllerInfo()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "fetching controller info")
|
||||
return fmt.Errorf("error fetching controller info: %w", err)
|
||||
}
|
||||
|
||||
var updateParams params.UpdateControllerParams
|
||||
|
|
@ -176,7 +175,7 @@ func maybeUpdateURLsFromConfig(cfg config.Config, store common.Store) error {
|
|||
|
||||
_, err = store.UpdateController(updateParams)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "updating controller info")
|
||||
return fmt.Errorf("error updating controller info: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue