Skip to content

Commit

Permalink
fix: stop ignoring most of the errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed Apr 26, 2024
1 parent 4b9a12f commit fd91446
Show file tree
Hide file tree
Showing 27 changed files with 192 additions and 63 deletions.
6 changes: 5 additions & 1 deletion cmds/demoplugin/accessmethods/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ func (a *AccessMethod) ComposeAccessSpecification(p ppi.Plugin, opts ppi.Config,
func (a *AccessMethod) Reader(p ppi.Plugin, spec ppi.AccessSpec, creds credentials.Credentials) (io.ReadCloser, error) {
my := spec.(*AccessSpec)

cfg, _ := p.GetConfig()
cfg, err := p.GetConfig()
if err != nil {
return nil, errors.Wrapf(err, "can't get config for access method %s", my.MediaType)
}

root := os.TempDir()
if cfg != nil && cfg.(*config.Config).AccessMethods.Path != "" {
root = cfg.(*config.Config).Uploaders.Path
Expand Down
6 changes: 5 additions & 1 deletion cmds/demoplugin/uploaders/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ func (a *Uploader) Writer(p ppi.Plugin, arttype, mediatype, hint string, repo pp
var file *os.File
var err error

cfg, _ := p.GetConfig()
cfg, err := p.GetConfig()
if err != nil {
return nil, nil, errors.Wrapf(err, "can't get config for access method %s", mediatype)
}

root := os.TempDir()
if cfg != nil && cfg.(*config.Config).Uploaders.Path != "" {
root = cfg.(*config.Config).Uploaders.Path
Expand Down
15 changes: 12 additions & 3 deletions cmds/ocm/commands/misccmds/rsakeypair/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ func (o *Command) Complete(args []string) error {
if o.rootcerts != "" {
pool, err := signutils.GetCertPool(o.rootcerts, false)
if err != nil {
path, _ := utils2.ResolvePath(o.rootcerts)
path, err := utils2.ResolvePath(o.rootcerts)
if err != nil {
return errors.Wrapf(err, "failed to resolve root certificates")
}
data, err := vfs.ReadFile(o.Context.FileSystem(), path)
if err != nil {
return errors.Wrapf(err, "cannot read root cert file %q", o.rootcerts)
Expand Down Expand Up @@ -190,7 +193,10 @@ func (o *Command) Complete(args []string) error {
raw := []byte(o.cacert)
cert, pool, err := signutils.GetCertificate(o.cacert, false)
if err != nil {
path, _ := utils2.ResolvePath(o.cacert)
path, err := utils2.ResolvePath(o.cacert)
if err != nil {
return errors.Wrapf(err, "failed to resolve cacert file %q", o.cacert)
}
data, err := vfs.ReadFile(o.Context.FileSystem(), path)
if err != nil {
return errors.Wrapf(err, "cannot read ca cert file %q", o.cacert)
Expand Down Expand Up @@ -222,7 +228,10 @@ func (o *Command) Complete(args []string) error {
if o.cakey != "" {
key, err := parse.ParsePrivateKey(o.cakey)
if err != nil {
path, _ := utils2.ResolvePath(o.cakey)
path, err := utils2.ResolvePath(o.cakey)
if err != nil {
return errors.Wrapf(err, "failed to resolve ca key file %q", o.cakey)
}
data, err := vfs.ReadFile(o.Context.FileSystem(), path)
if err != nil {
return errors.Wrapf(err, "cannot read private key file %q", o.cakey)
Expand Down
17 changes: 14 additions & 3 deletions cmds/ocm/commands/ocicmds/common/handlers/artifacthdlr/attached.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ func Attachment(d digest.Digest, suffix string) string {
var ExplodeAttached = processing.Explode(explodeAttached)

func explodeAttached(o interface{}) []interface{} {
obj := o.(*Object)
obj, ok := o.(*Object)
if !ok {
return nil
}
result := []interface{}{o}
blob, _ := obj.Artifact.Blob()
blob, err := obj.Artifact.Blob()
if err != nil {
return result
}
dig := blob.Digest()
prefix := Attachment(dig, "")
list, err := obj.Namespace.ListTags()
Expand All @@ -38,9 +44,14 @@ func explodeAttached(o interface{}) []interface{} {
s := obj.Spec
s.Tag = &t
s.Digest = nil
key, err := Key(a)
if err != nil {
// this is questionable behaviour. :think:
return nil
}
att := &Object{
History: hist,
Key: Key(a),
Key: key,
Spec: s,
AttachKind: l[len(prefix):],
Namespace: obj.Namespace,
Expand Down
10 changes: 8 additions & 2 deletions cmds/ocm/commands/ocicmds/common/handlers/artifacthdlr/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ func clean(iterable data.Iterable) data.Iterable {
e := it.Next().(*Object)
data.Add(e)
l := len(e.History)
blob, _ := e.Artifact.Blob()
blob, err := e.Artifact.Blob()
if err != nil {
return nil
}

if l > depth[blob.Digest()] {
depth[blob.Digest()] = l
Expand All @@ -43,7 +46,10 @@ func clean(iterable data.Iterable) data.Iterable {

output.Print(data, "clean in")
for i := 0; i < len(data); i++ {
e := data[i].(*Object)
e, ok := data[i].(*Object)
if !ok {
return nil
}
l := len(e.History)
blob, _ := e.Artifact.Blob()
dig := blob.Digest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ func ClosureExplode(opts *output.Options, e interface{}) []interface{} {
}

func traverse(hist common.History, o *Object, octx out.Context) []output.Object {
blob, _ := o.Artifact.Blob()
blob, err := o.Artifact.Blob()
if err != nil {
return nil
}
key := common.NewNameVersion("", blob.Digest().String())
if err := hist.Add(oci.KIND_OCIARTIFACT, key); err != nil {
return nil
Expand All @@ -38,9 +41,13 @@ func traverse(hist common.History, o *Object, octx out.Context) []output.Object
if err != nil {
out.Errf(octx, "Warning: lookup nested artifact %q [%s]: %s\n", ref.Digest, hist, err)
}
version, err := Key(nested)
if err != nil {
out.Errf(octx, "Failed to find nested key %q [%s]: %s\n", ref.Digest, hist, err)
}
obj := &Object{
History: hist.Copy(),
Key: Key(nested),
Key: version,
Spec: oci.RefSpec{
UniformRepositorySpec: o.Spec.UniformRepositorySpec,
ArtSpec: oci.ArtSpec{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ func (o *Object) GetKind() string {
}

func (o *Object) IsNode() *common.NameVersion {
blob, _ := o.Artifact.Blob()
blob, err := o.Artifact.Blob()
if err != nil {
return nil
}
nv := common.NewNameVersion("", blob.Digest().String())
return &nv
}
Expand All @@ -73,7 +76,11 @@ func (o *Object) AsManifest() interface{} {
}

func (o *Object) String() string {
blob, _ := o.Artifact.Blob()
blob, err := o.Artifact.Blob()
if err != nil {
return ""
}

dig := blob.Digest()
tag := "-"
if o.Spec.Tag != nil {
Expand All @@ -90,9 +97,13 @@ type Manifest struct {

////////////////////////////////////////////////////////////////////////////////

func Key(a oci.ArtifactAccess) common.NameVersion {
blob, _ := a.Blob()
return common.NewNameVersion("", blob.Digest().String())
func Key(a oci.ArtifactAccess) (common.NameVersion, error) {
blob, err := a.Blob()
if err != nil {
return common.NameVersion{}, fmt.Errorf("unable to determine blob name: %w", err)
}

return common.NewNameVersion("", blob.Digest().String()), nil
}

type TypeHandler struct {
Expand Down Expand Up @@ -165,8 +176,13 @@ func (h *TypeHandler) get(repo oci.Repository, elemspec utils.ElemSpec) ([]outpu
spec = evaluated.Ref
namespace = evaluated.Namespace
if evaluated.Artifact != nil {
key, err := Key(evaluated.Artifact)
if err != nil {
return nil, fmt.Errorf("unable to determine key for artifact %q: %w", name, err)
}

obj := &Object{
Key: Key(evaluated.Artifact),
Key: key,
Spec: spec,
Namespace: namespace,
Artifact: evaluated.Artifact,
Expand Down Expand Up @@ -198,8 +214,12 @@ func (h *TypeHandler) get(repo oci.Repository, elemspec utils.ElemSpec) ([]outpu
return nil, err
}
h.session.AddCloser(a)
key, err := Key(a)
if err != nil {
return nil, fmt.Errorf("unable to determine key for artifact %q: %w", name, err)
}
obj := &Object{
Key: Key(a),
Key: key,
Spec: spec,
Namespace: namespace,
Artifact: a,
Expand All @@ -219,8 +239,13 @@ func (h *TypeHandler) get(repo oci.Repository, elemspec utils.ElemSpec) ([]outpu
t := tag
s := spec
s.Tag = &t
key, err := Key(a)
if err != nil {
return nil, fmt.Errorf("unable to determine key for artifact %q: %w", name, err)
}

result = append(result, &Object{
Key: Key(a),
Key: key,
Spec: s,
Namespace: namespace,
Artifact: a,
Expand Down
18 changes: 11 additions & 7 deletions cmds/ocm/commands/ocmcmds/common/addconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,27 @@ func (o *ResourceConfigAdderCommand) ProcessResourceDescriptions(h ResourceSpecH
listkey := utils.Plural(h.Key(), 0)

var current string
configFile, _ := utils2.ResolvePath(o.ConfigFile)
if ok, err := vfs.FileExists(fs, configFile); ok {
configFile, err := utils2.ResolvePath(o.ConfigFile)
if err != nil {
return errors.Wrapf(err, "failed to resolve config file %s", o.ConfigFile)
}

ok, err := vfs.FileExists(fs, configFile)
if err != nil {
return errors.Wrapf(err, "cannot read %s config file %q", listkey, o.ConfigFile)
}

if ok {
fi, err := fs.Stat(configFile)
if err != nil {
return errors.Wrapf(err, "cannot stat %s config file %q", listkey, o.ConfigFile)
}
mode = fi.Mode().Perm()
if err != nil {
return err
}
data, err := vfs.ReadFile(fs, configFile)
if err != nil {
return errors.Wrapf(err, "cannot read %s config file %q", listkey, o.ConfigFile)
}
current = string(data)
} else if err != nil {
return errors.Wrapf(err, "cannot read %s config file %q", listkey, o.ConfigFile)
}

for _, source := range o.Resources {
Expand Down
16 changes: 11 additions & 5 deletions cmds/ocm/commands/ocmcmds/common/handlers/comphdlr/typehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,22 @@ func (h *TypeHandler) Get(elemspec utils.ElemSpec) ([]output.Object, error) {
return h.get(h.repobase, elemspec)
}

func (h *TypeHandler) filterVersions(vers []string) []string {
func (h *TypeHandler) filterVersions(vers []string) ([]string, error) {
if len(h.constraints) == 0 && !h.latest {
return vers
return vers, nil
}
versions, err := semverutils.MatchVersionStrings(vers, h.constraints...)
if err != nil {
return nil, fmt.Errorf("invalid constraints: %v", err)
}
versions, _ := semverutils.MatchVersionStrings(vers, h.constraints...)
if h.latest && len(versions) > 1 {
versions = versions[len(versions)-1:]
}
vers = nil
for _, v := range versions {
vers = append(vers, v.Original())
}
return vers
return vers, nil
}

func (h *TypeHandler) get(repo ocm.Repository, elemspec utils.ElemSpec) ([]output.Object, error) {
Expand Down Expand Up @@ -228,7 +231,10 @@ func (h *TypeHandler) get(repo ocm.Repository, elemspec utils.ElemSpec) ([]outpu
if err != nil {
return nil, err
}
versions = h.filterVersions(versions)
versions, err = h.filterVersions(versions)
if err != nil {
return nil, err
}

for _, vers := range versions {
v, err := h.session.GetComponentVersion(component, vers)
Expand Down
16 changes: 11 additions & 5 deletions cmds/ocm/commands/ocmcmds/common/handlers/vershdlr/typehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,22 @@ func (h *TypeHandler) Get(elemspec utils.ElemSpec) ([]output.Object, error) {
return h.get(h.repobase, elemspec)
}

func (h *TypeHandler) filterVersions(vers []string) []string {
func (h *TypeHandler) filterVersions(vers []string) ([]string, error) {
if len(h.constraints) == 0 && !h.latest {
return vers
return vers, nil
}
versions, err := semverutils.MatchVersionStrings(vers, h.constraints...)
if err != nil {
return nil, err
}
versions, _ := semverutils.MatchVersionStrings(vers, h.constraints...)
if h.latest && len(versions) > 1 {
versions = versions[len(versions)-1:]
}
vers = nil
for _, v := range versions {
vers = append(vers, v.Original())
}
return vers
return vers, nil
}

func (h *TypeHandler) get(repo ocm.Repository, elemspec utils.ElemSpec) ([]output.Object, error) {
Expand Down Expand Up @@ -215,7 +218,10 @@ func (h *TypeHandler) get(repo ocm.Repository, elemspec utils.ElemSpec) ([]outpu
if err != nil {
return nil, err
}
versions = h.filterVersions(versions)
versions, err = h.filterVersions(versions)
if err != nil {
return nil, err
}

for _, vers := range versions {
t := vers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (o *Option) GetPath(args []string, fss ...vfs.FileSystem) (string, []string
if ok, err := vfs.Exists(fs, args[0]); !ok || err != nil {
return o.Path, args
}
// ignored: I can't rewrite this whole segment.
if ok, _ := vfs.IsDir(fs, args[0]); ok {
return args[0], args[1:]
}
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/ocmcmds/common/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func (a *ContentResourceSpecificationsProvider) Get() (string, error) {
}

//nolint:errchkjson // We don't care about this error.
r, _ := json.Marshal(data)
r, err := json.Marshal(data)
return string(r), nil
}

Expand Down
7 changes: 6 additions & 1 deletion cmds/ocm/commands/ocmcmds/plugins/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ func DescribePlugin(p plugin.Plugin, out common.Printer) {
out.Printf(" Version: %s\n", src.Version)
out.Printf(" Resource: %s\n", src.Resource)
u := src.Repository.AsUniformSpec(p.Context())
data, _ := json.Marshal(src.Repository)
data, err := json.Marshal(src.Repository)
if err != nil {
out.Printf("Status: %s\n", err)

return
}
out.Printf(" Repository: %s\n", u.String())
out.Printf(" Specification: %s\n", string(data))
} else {
Expand Down
7 changes: 6 additions & 1 deletion cmds/ocm/commands/toicmds/package/bootstrap/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ func (o *Command) Complete(args []string) error {
return errors.Wrapf(err, "bootstrap resource identity pattern")
}
if len(o.CredentialsFile) == 0 {
if ok, _ := vfs.FileExists(o.FileSystem(), DEFAULT_CREDENTIALS_FILE); ok {
ok, err := vfs.FileExists(o.FileSystem(), DEFAULT_CREDENTIALS_FILE)
if err != nil {
return err
}

if ok {
o.CredentialsFile = DEFAULT_CREDENTIALS_FILE
}
}
Expand Down
Loading

0 comments on commit fd91446

Please sign in to comment.