Skip to content
This repository was archived by the owner on Jun 26, 2024. It is now read-only.

Commit c718d35

Browse files
🌱 Use maximum verbosity for errors in command/get.go (#75)
* 🌱 Use maximum verbosity for errors in command/get.go * 🌱 Fix typo, use checksum variable * πŸ› Fix linter * Update command/get.go Co-authored-by: Wilson E. Husin <[email protected]> * Update command/get.go Co-authored-by: Wilson E. Husin <[email protected]> * Update command/get.go Co-authored-by: Wilson E. Husin <[email protected]> * 🌱 Remove extraneous fmt.Errorf for symLink err Co-authored-by: Wilson E. Husin <[email protected]>
1 parent c5f0d3d commit c718d35

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

β€Žcommand/get.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package command
1616

1717
import (
1818
"context"
19+
"fmt"
1920
"os"
2021
"path/filepath"
2122
"time"
@@ -62,13 +63,19 @@ func symlink(binDir, progDir string, p *program.Lock) error {
6263
func Get(ctx context.Context, conf *config.Runtime, p *program.Lock) error {
6364
archiveName, err := p.ArchiveName(conf.OS, conf.Arch)
6465
if err != nil {
65-
return err
66+
return fmt.Errorf("get archive name: %w", err)
67+
}
68+
69+
checksum, ok := p.Checksums[archiveName]
70+
if !ok {
71+
return fmt.Errorf("unrecognized checksum reference '%s'", archiveName)
6672
}
6773

68-
progDir := filepath.Join(conf.ProgDir, p.Checksums[archiveName].Binary+"-"+p.Name)
74+
progDir := filepath.Join(conf.ProgDir, checksum.Binary+"-"+p.Name)
6975
if err := Verify(ctx, conf, p); err == nil {
7076
// Re-run symlink to renew atime and mtime, so that GNU Make will not rebuild in the future
7177
internal.Log().Debug().Str("program", p.Name).Msg("found valid existing, re-linking")
78+
// symLink already returns context in the error
7279
return symlink(conf.BinDir, progDir, p)
7380
}
7481

@@ -90,24 +97,27 @@ func Get(ctx context.Context, conf *config.Runtime, p *program.Lock) error {
9097

9198
a, err := p.DownloadArchive(ctx, &download.HTTP{UseCache: conf.UseCache}, conf.OS, conf.Arch)
9299
if err != nil {
93-
return err
100+
return fmt.Errorf("download archive: %w", err)
94101
}
102+
95103
internal.Log().Debug().Str("program", p.Name).Msg("extracting archive")
96104
bin, err := a.Extract(p.Name)
97105
if err != nil {
98-
return err
106+
return fmt.Errorf("extract archive: %w", err)
99107
}
108+
100109
internal.Log().Debug().Str("program", p.Name).Msg("found binary")
101110

102111
fullProgDir := filepath.Join(conf.BinDir, progDir)
103-
if err = os.MkdirAll(fullProgDir, 0755); err != nil {
104-
return err
112+
if err := os.MkdirAll(fullProgDir, 0755); err != nil {
113+
return fmt.Errorf("ensuring directory existence '%s': %w", fullProgDir, err)
105114
}
115+
106116
binPath := filepath.Join(fullProgDir, p.Name)
107-
err = os.WriteFile(binPath, bin, 0755)
108-
if err != nil {
109-
return err
117+
if err := os.WriteFile(binPath, bin, 0755); err != nil {
118+
return fmt.Errorf("write file '%s': %w", binPath, err)
110119
}
120+
111121
internal.Log().Debug().Str("output", binPath).Str("program", p.Name).Msg("downloaded")
112122

113123
return symlink(conf.BinDir, progDir, p)

0 commit comments

Comments
Β (0)