Skip to content

Commit

Permalink
Clean up error handling in export command
Browse files Browse the repository at this point in the history
  • Loading branch information
amisevsk committed Feb 20, 2024
1 parent 50adb5e commit f527da0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/cmd/export/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package export

import (
"context"
"errors"
"fmt"
"jmm/pkg/lib/storage"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"oras.land/oras-go/v2"
"oras.land/oras-go/v2/content/oci"
"oras.land/oras-go/v2/errdef"
"oras.land/oras-go/v2/registry"
"oras.land/oras-go/v2/registry/remote"
)
Expand Down Expand Up @@ -120,7 +122,11 @@ func runCommand(opts *ExportOptions) func(*cobra.Command, []string) {
return
}

fmt.Printf("Exporting to %s\n", opts.exportDir)
exportTo := opts.exportDir
if exportTo == "" {
exportTo = "current directory"
}
fmt.Printf("Exporting to %s\n", exportTo)
err = ExportModel(cmd.Context(), store, opts.modelRef, opts.exportDir, opts.exportConf)
if err != nil {
fmt.Println(err)
Expand Down Expand Up @@ -154,7 +160,10 @@ func getStoreForRef(ctx context.Context, opts *ExportOptions) (oras.Target, erro
return nil, fmt.Errorf("could not resolve repository %s in registry %s", opts.modelRef.Repository, opts.modelRef.Registry)
}
if _, err := repo.Resolve(ctx, opts.modelRef.Reference); err != nil {
return nil, fmt.Errorf("reference %s is not present in local storage and could not be found in remote", opts.modelRef.String())
if errors.Is(err, errdef.ErrNotFound) {
return nil, fmt.Errorf("reference %s is not present in local storage and could not be found in remote", opts.modelRef.String())
}
return nil, fmt.Errorf("unexpected error retrieving reference from remote: %w", err)
}

return repo, nil
Expand Down

0 comments on commit f527da0

Please sign in to comment.