refactor: return errors with stack traces, where appropriate
1 file changed, 10 insertions(+), 8 deletions(-)
changed files
M internal/fetcher/fetcher.go → internal/fetcher/fetcher.go
@@ -45,7 +45,7 @@ updater: options.Listener, } } -func (f *Fetcher) getArtefacts(run uint64) error { +func (f *Fetcher) getArtefacts(run uint64) errors.E { runID := strconv.FormatUint(run, 10) f.log.Debug("getting artefacts", "run_id", runID)@@ -70,7 +70,7 @@ return nil } -func (f *Fetcher) checkFolder() error { +func (f *Fetcher) checkFolder() errors.E { contents, err := os.ReadDir(f.options.Root) if err != nil { return errors.WithMessage(err, "could not read root directory")@@ -84,13 +84,15 @@ } } if len(badFiles) > 0 { - return errors.Basef("unexpected files in root directory: %s", strings.Join(badFiles, ", ")) + return errors.WithStack( + errors.Basef("unexpected files in root directory: %s", strings.Join(badFiles, ", ")), + ) } return nil } -func (f *Fetcher) CleanOldRevisions() error { +func (f *Fetcher) CleanOldRevisions() errors.E { contents, err := os.ReadDir(f.options.Root) if err != nil { return errors.WithMessage(err, "could not read root directory")@@ -125,7 +127,7 @@ } }() } -func (f *Fetcher) getFile(runID, basename string) error { +func (f *Fetcher) getFile(runID, basename string) errors.E { filename := filepath.Join(f.options.Root, runID, basename) url := f.options.FetchURL.JoinPath(runID, basename).String()@@ -162,7 +164,7 @@ return nil } -func (f *Fetcher) getCurrentVersion() (uint64, error) { +func (f *Fetcher) getCurrentVersion() (uint64, errors.E) { target, err := os.Readlink(filepath.Join(f.options.Root, "current")) if err != nil && errors.Is(err, fs.ErrNotExist) { return 0, errors.WithMessage(err, "could not stat current link")@@ -175,7 +177,7 @@ return f.current, nil } -func (f *Fetcher) initialiseStorage() (uint64, error) { +func (f *Fetcher) initialiseStorage() (uint64, errors.E) { latest, err := f.updater.GetLatestRunID() if err != nil { f.log.Warn("could not get latest run ID, using fallback", "error", err)@@ -196,7 +198,7 @@ return f.current, nil } -func (f *Fetcher) Subscribe() (<-chan string, error) { +func (f *Fetcher) Subscribe() (<-chan string, errors.E) { ch := make(chan string, 1) err := f.checkFolder() if err != nil {