diff --git a/config/config.go b/config/config.go index 2e6ac5f6..96442cf4 100644 --- a/config/config.go +++ b/config/config.go @@ -106,35 +106,35 @@ type Config struct { // Validate validates the config func (c *Config) Validate() error { if err := c.APIServer.Validate(); err != nil { - return errors.Wrap(err, "validating APIServer config") + return fmt.Errorf("error validating apiserver config: %w", err) } if err := c.Database.Validate(); err != nil { - return errors.Wrap(err, "validating database config") + return fmt.Errorf("error validating database config: %w", err) } if err := c.Default.Validate(); err != nil { - return errors.Wrap(err, "validating default section") + return fmt.Errorf("error validating default config: %w", err) } for _, gh := range c.Github { if err := gh.Validate(); err != nil { - return errors.Wrap(err, "validating github config") + return fmt.Errorf("error validating github config: %w", err) } } if err := c.JWTAuth.Validate(); err != nil { - return errors.Wrap(err, "validating jwt config") + return fmt.Errorf("error validating jwt_auth config: %w", err) } if err := c.Logging.Validate(); err != nil { - return errors.Wrap(err, "validating logging config") + return fmt.Errorf("error validating logging config: %w", err) } providerNames := map[string]int{} for _, provider := range c.Providers { if err := provider.Validate(); err != nil { - return errors.Wrap(err, "validating provider") + return fmt.Errorf("error validating provider %s: %w", provider.Name, err) } providerNames[provider.Name]++ } @@ -217,15 +217,15 @@ func (d *Default) Validate() error { } _, err := url.Parse(d.CallbackURL) if err != nil { - return errors.Wrap(err, "validating callback_url") + return fmt.Errorf("invalid callback_url: %w", err) } if d.MetadataURL == "" { - return fmt.Errorf("missing metadata-url") + return fmt.Errorf("missing metadata_url") } if _, err := url.Parse(d.MetadataURL); err != nil { - return errors.Wrap(err, "validating metadata_url") + return fmt.Errorf("invalid metadata_url: %w", err) } return nil @@ -253,7 +253,7 @@ func (a *GithubApp) Validate() error { } if _, err := os.Stat(a.PrivateKeyPath); err != nil { - return errors.Wrap(err, "accessing private_key_path") + return fmt.Errorf("error accessing private_key_path: %w", err) } // Read the private key as bytes keyBytes, err := os.ReadFile(a.PrivateKeyPath) @@ -341,7 +341,7 @@ func (g *Github) Validate() error { switch g.AuthType { case GithubAuthTypeApp: if err := g.App.Validate(); err != nil { - return errors.Wrap(err, "validating github app config") + return fmt.Errorf("invalid github app config: %w", err) } default: if g.OAuth2Token == "" && g.PAT.OAuth2Token == "" { @@ -427,7 +427,7 @@ func (p *Provider) Validate() error { switch p.ProviderType { case params.ExternalProvider: if err := p.External.Validate(); err != nil { - return errors.Wrap(err, "validating external provider info") + return fmt.Errorf("invalid external provider config: %w", err) } default: return fmt.Errorf("unknown provider type: %s", p.ProviderType) @@ -490,11 +490,11 @@ func (d *Database) Validate() error { switch d.DbBackend { case MySQLBackend: if err := d.MySQL.Validate(); err != nil { - return errors.Wrap(err, "validating mysql config") + return fmt.Errorf("validating mysql config: %w", err) } case SQLiteBackend: if err := d.SQLite.Validate(); err != nil { - return errors.Wrap(err, "validating sqlite3 config") + return fmt.Errorf("validating sqlite3 config: %w", err) } default: return fmt.Errorf("invalid database backend: %s", d.DbBackend) @@ -518,7 +518,7 @@ func (s *SQLite) Validate() error { parent := filepath.Dir(s.DBFile) if _, err := os.Stat(parent); err != nil { - return errors.Wrapf(err, "accessing db_file parent dir: %s", parent) + return fmt.Errorf("parent directory of db_file does not exist: %w", err) } return nil } @@ -632,7 +632,7 @@ func (a *APIServer) BindAddress() string { func (a *APIServer) Validate() error { if a.UseTLS { if err := a.TLSConfig.Validate(); err != nil { - return errors.Wrap(err, "TLS validation failed") + return fmt.Errorf("invalid tls config: %w", err) } } if a.Port > 65535 || a.Port < 1 { @@ -677,7 +677,7 @@ func (d *timeToLive) Duration() time.Duration { func (d *timeToLive) UnmarshalText(text []byte) error { _, err := time.ParseDuration(string(text)) if err != nil { - return errors.Wrap(err, "parsing time_to_live") + return fmt.Errorf("invalid duration: %w", err) } *d = timeToLive(text) @@ -693,7 +693,7 @@ type JWTAuth struct { // Validate validates the JWTAuth config func (j *JWTAuth) Validate() error { if _, err := j.TimeToLive.ParseDuration(); err != nil { - return errors.Wrap(err, "parsing duration") + return fmt.Errorf("invalid time_to_live: %w", err) } if j.Secret == "" { diff --git a/config/config_test.go b/config/config_test.go index 2d2cf34d..8a2eac05 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -153,7 +153,7 @@ func TestDefaultSectionConfig(t *testing.T) { CallbackURL: cfg.CallbackURL, MetadataURL: "", }, - errString: "missing metadata-url", + errString: "missing metadata_url", }, } @@ -231,7 +231,7 @@ func TestValidateAPIServerConfig(t *testing.T) { TLSConfig: TLSConfig{}, UseTLS: true, }, - errString: "TLS validation failed:*", + errString: "invalid tls config: missing crt or key", }, { name: "Skip TLS config validation if UseTLS is false", @@ -434,7 +434,7 @@ func TestSQLiteConfig(t *testing.T) { cfg: SQLite{ DBFile: "/i/dont/exist/test.db", }, - errString: "accessing db_file parent dir:.*no such file or directory", + errString: "parent directory of db_file does not exist: stat.*", }, } @@ -489,7 +489,7 @@ func TestJWTAuthConfig(t *testing.T) { Secret: cfg.Secret, TimeToLive: "bogus", }, - errString: "parsing duration: time: invalid duration*", + errString: "invalid time_to_live: time: invalid duration*", }, } diff --git a/config/external.go b/config/external.go index 66458868..9f592fb3 100644 --- a/config/external.go +++ b/config/external.go @@ -20,8 +20,6 @@ import ( "path/filepath" "strings" - "github.com/pkg/errors" - "github.com/cloudbase/garm-provider-common/util/exec" ) @@ -88,10 +86,10 @@ func (e *External) Validate() error { execPath, err := e.ExecutablePath() if err != nil { - return errors.Wrap(err, "fetching executable path") + return fmt.Errorf("failed to get executable path: %w", err) } if _, err := os.Stat(execPath); err != nil { - return errors.Wrap(err, "checking provider executable") + return fmt.Errorf("failed to access external provider binary %s", execPath) } if !exec.IsExecutable(execPath) { return fmt.Errorf("external provider binary %s is not executable", execPath) diff --git a/config/external_test.go b/config/external_test.go index 17dc04ba..68ca3636 100644 --- a/config/external_test.go +++ b/config/external_test.go @@ -78,7 +78,7 @@ func TestExternal(t *testing.T) { ConfigFile: "", ProviderDir: "../test", }, - errString: "fetching executable path: executable path must be an absolute path", + errString: "failed to get executable path: executable path must be an absolute path", }, { name: "Provider executable path must be absolute", @@ -86,7 +86,7 @@ func TestExternal(t *testing.T) { ConfigFile: "", ProviderExecutable: "../test", }, - errString: "fetching executable path: executable path must be an absolute path", + errString: "failed to get executable path: executable path must be an absolute path", }, { name: "Provider executable not found", @@ -94,7 +94,7 @@ func TestExternal(t *testing.T) { ConfigFile: "", ProviderDir: "/tmp", }, - errString: "checking provider executable: stat /tmp/garm-external-provider: no such file or directory", + errString: "failed to access external provider binary /tmp/garm-external-provider", }, }