Skip to content

Revert "nix: improve redacted nix error (#1776)" #1778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions internal/nix/nix.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/pkg/errors"
"go.jetpack.io/devbox/internal/boxcli/featureflag"
"go.jetpack.io/devbox/internal/boxcli/usererr"
"go.jetpack.io/devbox/internal/redact"

"go.jetpack.io/devbox/internal/debug"
)
Expand Down Expand Up @@ -82,22 +81,15 @@ func (*Nix) PrintDevEnv(ctx context.Context, args *PrintDevEnvArgs) (*PrintDevEn
if insecure, insecureErr := IsExitErrorInsecurePackage(err, "" /*installable*/); insecure {
return nil, insecureErr
} else if err != nil {
safeArgs := make([]string, 0, len(cmd.Args))
for _, a := range cmd.Args {
if a == args.FlakeDir {
a = "<redacted path>"
}
safeArgs = append(safeArgs, a)
}
return nil, redact.Errorf("nix command: %s", redact.Safe(safeArgs))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fumbled this with the original PR. I was going to try and sanitize the individual args, but then decided not to and ended up with a weird in between implementation. The line was supposed to just be:

redact.Errorf("nix command: %s", redact.Safe(cmd))

and not have the safeArgs stuff.

Redacted error messages are not normally redacted and retain their normal message unless they're sent to Sentry. But here I modified the actual slice of args, so it ended up always redacted.

If this isn't blocking anything, I can just submit a fix PR later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I see. I need to learn about our redact logic more.

Assuming it's okay, I'm going to land this, just so that the Devbox release is unblocked. Since it's a small PR, perhaps you could re-submit with the better fix and if it works out timing-wise then it could be included in the release as well!

return nil, errors.Wrapf(err, "Command: %s", cmd)
}

if err := json.Unmarshal(data, &out); err != nil {
return nil, redact.Errorf("unmarshal nix print-dev-env output: %w", redact.Safe(err))
return nil, errors.WithStack(err)
}

if err = savePrintDevEnvCache(args.PrintDevEnvCachePath, out); err != nil {
return nil, redact.Errorf("savePrintDevEnvCache: %w", redact.Safe(err))
return nil, errors.WithStack(err)
}
}

Expand Down Expand Up @@ -188,13 +180,12 @@ func Version() (string, error) {
cmd := command("--version")
outBytes, err := cmd.Output()
if err != nil {
return "", redact.Errorf("nix command: %s", redact.Safe(cmd))
return "", errors.WithStack(err)
}
out := string(outBytes)
const prefix = "nix (Nix) "
if !strings.HasPrefix(out, prefix) {
return "", redact.Errorf(`nix command %s: expected %q prefix, but output was: %s`,
redact.Safe(cmd), redact.Safe(prefix), redact.Safe(out))
return "", errors.Errorf(`Expected "%s" prefix, but output from nix --version was: %s`, prefix, out)
}
version = strings.TrimSpace(strings.TrimPrefix(out, prefix))
return version, nil
Expand Down