all repos — searchix @ 9015baf955c94a806c01b3dcd5648c8e68ad2685

Search engine for NixOS, nix-darwin, home-manager and NUR users

refactor: ensure errors have stack traces

Alan Pearce
commit

9015baf955c94a806c01b3dcd5648c8e68ad2685

parent

7bb77ff5729cc9434afee895a470fd3b4c12e6d1

1 file changed, 9 insertions(+), 16 deletions(-)

changed files
M internal/fetcher/channel.gointernal/fetcher/channel.go
@@ -14,7 +14,7 @@ "go.alanpearce.eu/searchix/internal/config"
"go.alanpearce.eu/searchix/internal/index" "go.alanpearce.eu/x/log" - "github.com/pkg/errors" + "gitlab.com/tozd/go/errors" ) type ChannelFetcher struct {
@@ -26,7 +26,7 @@
func NewChannelFetcher( source *config.Source, logger *log.Logger, -) (*ChannelFetcher, error) { +) (*ChannelFetcher, errors.E) { switch source.Importer { case config.Options: return &ChannelFetcher{
@@ -34,14 +34,14 @@ Source: source,
Logger: logger, }, nil default: - return nil, fmt.Errorf("unsupported importer type %s", source.Importer) + return nil, errors.Errorf("unsupported importer type %s", source.Importer) } } func (i *ChannelFetcher) FetchIfNeeded( ctx context.Context, sourceMeta *index.SourceMeta, -) (f FetchedFiles, err error) { +) (*FetchedFiles, errors.E) { args := []string{ "--no-build-output", "--timeout",
@@ -58,12 +58,9 @@ }
i.Logger.Debug("nix-build command", "args", args) cmd := exec.CommandContext(ctx, "nix-build", args...) - var out []byte - out, err = cmd.Output() + out, err := cmd.Output() if err != nil { - err = errors.WithMessage(err, "failed to run nix-build (--dry-run)") - - return + return nil, errors.WithMessage(err, "failed to run nix-build (--dry-run)") } outPath := path.Join(strings.TrimSpace(string(out)), i.Source.OutputPath, "options.json")
@@ -80,14 +77,10 @@ }
file, err := os.Open(outPath) if err != nil { - err = errors.WithMessage(err, "failed to open options.json") - - return + return nil, errors.WithMessage(err, "failed to open options.json") } - f = FetchedFiles{ + return &FetchedFiles{ Options: file, - } - - return + }, nil }