diff --git a/cmd/traefik/plugins.go b/cmd/traefik/plugins.go index f94535f92..c2b847819 100644 --- a/cmd/traefik/plugins.go +++ b/cmd/traefik/plugins.go @@ -35,12 +35,12 @@ func initPlugins(staticCfg *static.Configuration) (*plugins.Client, map[string]p var err error client, err = plugins.NewClient(opts) if err != nil { - return nil, nil, nil, err + return nil, nil, nil, fmt.Errorf("unable to create plugins client: %w", err) } err = plugins.SetupRemotePlugins(client, staticCfg.Experimental.Plugins) if err != nil { - return nil, nil, nil, err + return nil, nil, nil, fmt.Errorf("unable to set up plugins environment: %w", err) } plgs = staticCfg.Experimental.Plugins diff --git a/pkg/plugins/client.go b/pkg/plugins/client.go index e891da5c4..4fcdd1ab4 100644 --- a/pkg/plugins/client.go +++ b/pkg/plugins/client.go @@ -264,7 +264,7 @@ func (c *Client) unzipArchive(pName, pVersion string) error { for _, f := range archive.File { err = unzipFile(f, dest) if err != nil { - return err + return fmt.Errorf("unable to unzip %s: %w", f.Name, err) } } @@ -283,12 +283,17 @@ func unzipFile(f *zipa.File, dest string) error { p := filepath.Join(dest, pathParts[1]) if f.FileInfo().IsDir() { - return os.MkdirAll(p, f.Mode()) + err = os.MkdirAll(p, f.Mode()) + if err != nil { + return fmt.Errorf("unable to create archive directory %s: %w", p, err) + } + + return nil } err = os.MkdirAll(filepath.Dir(p), 0o750) if err != nil { - return err + return fmt.Errorf("unable to create archive directory %s for file %s: %w", filepath.Dir(p), p, err) } elt, err := os.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) @@ -347,7 +352,7 @@ func (c *Client) WriteState(plugins map[string]Descriptor) error { mp, err := json.MarshalIndent(m, "", " ") if err != nil { - return err + return fmt.Errorf("unable to marshal plugin state: %w", err) } return os.WriteFile(c.stateFile, mp, 0o600) @@ -361,10 +366,15 @@ func (c *Client) ResetAll() error { err := resetDirectory(filepath.Join(c.goPath, "..")) if err != nil { - return err + return fmt.Errorf("unable to reset plugins GoPath directory %s: %w", c.goPath, err) } - return resetDirectory(c.archives) + err = resetDirectory(c.archives) + if err != nil { + return fmt.Errorf("unable to reset plugins archives directory: %w", err) + } + + return nil } func (c *Client) buildArchivePath(pName, pVersion string) string { @@ -374,12 +384,12 @@ func (c *Client) buildArchivePath(pName, pVersion string) string { func resetDirectory(dir string) error { dirPath, err := filepath.Abs(dir) if err != nil { - return err + return fmt.Errorf("unable to get absolute path of %s: %w", dir, err) } currentPath, err := os.Getwd() if err != nil { - return err + return fmt.Errorf("unable to get the current directory: %w", err) } if strings.HasPrefix(currentPath, dirPath) { @@ -388,10 +398,15 @@ func resetDirectory(dir string) error { err = os.RemoveAll(dir) if err != nil { - return err + return fmt.Errorf("unable to remove directory %s: %w", dirPath, err) } - return os.MkdirAll(dir, 0o755) + err = os.MkdirAll(dir, 0o755) + if err != nil { + return fmt.Errorf("unable to create directory %s: %w", dirPath, err) + } + + return nil } func computeHash(filepath string) (string, error) { diff --git a/pkg/plugins/plugins.go b/pkg/plugins/plugins.go index fdfb9fbce..6888ceea4 100644 --- a/pkg/plugins/plugins.go +++ b/pkg/plugins/plugins.go @@ -21,7 +21,7 @@ func SetupRemotePlugins(client *Client, plugins map[string]Descriptor) error { err = client.CleanArchives(plugins) if err != nil { - return fmt.Errorf("failed to clean archives: %w", err) + return fmt.Errorf("unable to clean archives: %w", err) } ctx := context.Background() @@ -32,27 +32,27 @@ func SetupRemotePlugins(client *Client, plugins map[string]Descriptor) error { hash, err := client.Download(ctx, desc.ModuleName, desc.Version) if err != nil { _ = client.ResetAll() - return fmt.Errorf("failed to download plugin %s: %w", desc.ModuleName, err) + return fmt.Errorf("unable to download plugin %s: %w", desc.ModuleName, err) } err = client.Check(ctx, desc.ModuleName, desc.Version, hash) if err != nil { _ = client.ResetAll() - return fmt.Errorf("failed to check archive integrity of the plugin %s: %w", desc.ModuleName, err) + return fmt.Errorf("unable to check archive integrity of the plugin %s: %w", desc.ModuleName, err) } } err = client.WriteState(plugins) if err != nil { _ = client.ResetAll() - return fmt.Errorf("failed to write plugins state: %w", err) + return fmt.Errorf("unable to write plugins state: %w", err) } for _, desc := range plugins { err = client.Unzip(desc.ModuleName, desc.Version) if err != nil { _ = client.ResetAll() - return fmt.Errorf("failed to unzip archive: %w", err) + return fmt.Errorf("unable to unzip archive: %w", err) } }