Merge pull request #5851 from thaJeztah/err_handle_explicit

explicitly handle errors when wrapping them
This commit is contained in:
Sebastiaan van Stijn 2025-02-26 16:23:35 +01:00 committed by GitHub
commit b414752ef8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 8 deletions

View File

@ -76,9 +76,9 @@ func (c *Context) preFormat() {
func (c *Context) parseFormat() (*template.Template, error) { func (c *Context) parseFormat() (*template.Template, error) {
tmpl, err := templates.Parse(c.finalFormat) tmpl, err := templates.Parse(c.finalFormat)
if err != nil { if err != nil {
return tmpl, errors.Wrap(err, "template parsing error") return nil, errors.Wrap(err, "template parsing error")
} }
return tmpl, err return tmpl, nil
} }
func (c *Context) postFormat(tmpl *template.Template, subContext SubContext) { func (c *Context) postFormat(tmpl *template.Template, subContext SubContext) {

View File

@ -210,8 +210,10 @@ func newVersionTemplate(templateFormat string) (*template.Template, error) {
} }
tmpl := templates.New("version").Funcs(template.FuncMap{"getDetailsOrder": getDetailsOrder}) tmpl := templates.New("version").Funcs(template.FuncMap{"getDetailsOrder": getDetailsOrder})
tmpl, err := tmpl.Parse(templateFormat) tmpl, err := tmpl.Parse(templateFormat)
if err != nil {
return tmpl, errors.Wrap(err, "template parsing error") return nil, errors.Wrap(err, "template parsing error")
}
return tmpl, nil
} }
func getDetailsOrder(v types.ComponentVersion) []string { func getDetailsOrder(v types.ComponentVersion) []string {

View File

@ -67,7 +67,10 @@ func recursiveInterpolate(value any, path Path, opts Options) (any, error) {
return newValue, nil return newValue, nil
} }
casted, err := caster(newValue) casted, err := caster(newValue)
if err != nil {
return casted, newPathError(path, errors.Wrap(err, "failed to cast to expected type")) return casted, newPathError(path, errors.Wrap(err, "failed to cast to expected type"))
}
return casted, nil
case map[string]any: case map[string]any:
out := map[string]any{} out := map[string]any{}

View File

@ -121,8 +121,11 @@ func (c *client) PutManifest(ctx context.Context, ref reference.Named, manifest
} }
dgst, err := manifestService.Put(ctx, manifest, opts...) dgst, err := manifestService.Put(ctx, manifest, opts...)
if err != nil {
return dgst, errors.Wrapf(err, "failed to put manifest %s", ref) return dgst, errors.Wrapf(err, "failed to put manifest %s", ref)
} }
return dgst, nil
}
func (c *client) getRepositoryForReference(ctx context.Context, ref reference.Named, repoEndpoint repositoryEndpoint) (distribution.Repository, error) { func (c *client) getRepositoryForReference(ctx context.Context, ref reference.Named, repoEndpoint repositoryEndpoint) (distribution.Repository, error) {
repoName, err := reference.WithName(repoEndpoint.Name()) repoName, err := reference.WithName(repoEndpoint.Name())
@ -157,7 +160,10 @@ func (c *client) getHTTPTransportForRepoEndpoint(ctx context.Context, repoEndpoi
c.userAgent, c.userAgent,
repoEndpoint.actions, repoEndpoint.actions,
) )
return httpTransport, errors.Wrap(err, "failed to configure transport") if err != nil {
return nil, errors.Wrap(err, "failed to configure transport")
}
return httpTransport, nil
} }
// GetManifest returns an ImageManifest for the reference // GetManifest returns an ImageManifest for the reference

View File

@ -20,7 +20,10 @@ func parseCount(s string) (int, error) {
return -1, nil return -1, nil
} }
i, err := strconv.Atoi(s) i, err := strconv.Atoi(s)
return i, errors.Wrap(err, "count must be an integer") if err != nil {
return 0, errors.Wrap(err, "count must be an integer")
}
return i, nil
} }
// Set a new mount value // Set a new mount value