mirror of https://github.com/knative/func.git
Improve error messages (#913)
* Improve error messages Signed-off-by: Matej Vasek <mvasek@redhat.com> * incorporate review suggestion Co-authored-by: Lance Ball <lball@redhat.com> Co-authored-by: Lance Ball <lball@redhat.com>
This commit is contained in:
parent
56d93cfd9c
commit
3a7f388035
|
@ -175,7 +175,7 @@ func (r *Repositories) Add(name, uri string) (string, error) {
|
|||
// Create a repo (in-memory FS) from the URI
|
||||
repo, err := NewRepository(name, uri)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", fmt.Errorf("failed to create new repository: %w", err)
|
||||
}
|
||||
|
||||
// Error if the repository already exists on disk
|
||||
|
@ -186,7 +186,11 @@ func (r *Repositories) Add(name, uri string) (string, error) {
|
|||
|
||||
// Instruct the repository to write itself to disk at the given path.
|
||||
// Fails if path exists.
|
||||
return repo.Name, repo.Write(dest)
|
||||
err = repo.Write(dest)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to write repository: %w", err)
|
||||
}
|
||||
return repo.Name, nil
|
||||
}
|
||||
|
||||
// Rename a repository
|
||||
|
|
|
@ -139,7 +139,7 @@ func NewRepository(name, uri string) (r Repository, err error) {
|
|||
}
|
||||
r.FS, err = filesystemFromURI(uri) // Get a Filesystem from the URI
|
||||
if err != nil {
|
||||
return
|
||||
return Repository{}, fmt.Errorf("failed to get repository from URI (%q): %w", uri, err)
|
||||
}
|
||||
r, err = applyRepositoryManifest(r) // apply optional manifest to r
|
||||
if err != nil {
|
||||
|
@ -187,9 +187,9 @@ func filesystemFromRepo(uri string) (Filesystem, error) {
|
|||
})
|
||||
if err != nil {
|
||||
if isRepoNotFoundError(err) {
|
||||
err = nil // no repo at location is an expected condition
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("failed to clone repository: %w", err)
|
||||
}
|
||||
wt, err := clone.Worktree()
|
||||
if err != nil {
|
||||
|
@ -475,10 +475,10 @@ func (r *Repository) Write(path string) (err error) {
|
|||
if clone, err = git.PlainClone(tempDir, false, // not bare
|
||||
&git.CloneOptions{URL: r.uri, Depth: 1, Tags: git.NoTags,
|
||||
RecurseSubmodules: git.NoRecurseSubmodules}); err != nil {
|
||||
return
|
||||
return fmt.Errorf("failed to plain clone repository: %w", err)
|
||||
}
|
||||
if wt, err = clone.Worktree(); err != nil {
|
||||
return
|
||||
return fmt.Errorf("failed to get worktree: %w", err)
|
||||
}
|
||||
fs = billyFilesystem{fs: wt.Filesystem}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue