From 3f8d1b84f8f332e036b5bff39ef7dc00020c3986 Mon Sep 17 00:00:00 2001 From: Mike Landau Date: Thu, 28 Sep 2023 13:32:53 -0700 Subject: [PATCH 1/2] [errors] Show better errors when user script errors out and fix poetry plugin --- internal/boxcli/midcobra/midcobra.go | 1 + plugins/poetry.json | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/boxcli/midcobra/midcobra.go b/internal/boxcli/midcobra/midcobra.go index 5b8541fdd7e..5f34783b601 100644 --- a/internal/boxcli/midcobra/midcobra.go +++ b/internal/boxcli/midcobra/midcobra.go @@ -81,6 +81,7 @@ func (ex *midcobraExecutable) Execute(ctx context.Context, args []string) int { var exitErr *exec.ExitError var userExecErr *usererr.ExitError if errors.As(err, &userExecErr) { + ux.Ferror(ex.cmd.ErrOrStderr(), userExecErr.Error()+"\n") return userExecErr.ExitCode() } if errors.As(err, &exitErr) { diff --git a/plugins/poetry.json b/plugins/poetry.json index 681396074c9..5ee9833d987 100644 --- a/plugins/poetry.json +++ b/plugins/poetry.json @@ -1,7 +1,7 @@ { "name": "poetry", - "version": "0.0.1", - "readme": "This plugin automatically configures poetry to use the version of python installed in your Devbox shell, instead of the Python version that it is bundled with.", + "version": "0.0.2", + "readme": "This plugin automatically configures poetry to use the version of python installed in your Devbox shell, instead of the Python version that it is bundled with. Your pyproject.toml must be in the same directory as your devbox.json.", "env": { "POETRY_VIRTUALENVS_IN_PROJECT": "true", "POETRY_VIRTUALENVS_CREATE": "true", @@ -9,7 +9,7 @@ }, "shell": { "init_hook": [ - "poetry env use $(command -v python) --quiet --no-interaction" + "poetry env use $(command -v python) --no-interaction" ] } } From 105aaf201a6f732db9c5ab27ce7958d3df7d8427 Mon Sep 17 00:00:00 2001 From: Mike Landau Date: Thu, 28 Sep 2023 20:16:27 -0700 Subject: [PATCH 2/2] Use debug middleware --- internal/boxcli/midcobra/midcobra.go | 10 +--------- internal/boxcli/midcobra/telemetry.go | 7 +++++++ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/internal/boxcli/midcobra/midcobra.go b/internal/boxcli/midcobra/midcobra.go index 5f34783b601..aa3ffa170df 100644 --- a/internal/boxcli/midcobra/midcobra.go +++ b/internal/boxcli/midcobra/midcobra.go @@ -60,19 +60,12 @@ func (ex *midcobraExecutable) Execute(ctx context.Context, args []string) int { // Execute the cobra command: err := ex.cmd.Execute() - var postRunErr error - var userExecErr *usererr.ExitError - // If the error is from a user exec call, exclude such error from postrun hooks. - if err != nil && !errors.As(err, &userExecErr) { - postRunErr = err - } - // Run the 'post' hooks. Note that unlike the default PostRun cobra functionality these // run even if the command resulted in an error. This is useful when we still want to clean up // before the program exists or we want to log something. The error, if any, gets passed // to the post hook. for i := len(ex.middlewares) - 1; i >= 0; i-- { - ex.middlewares[i].postRun(ex.cmd, args, postRunErr) + ex.middlewares[i].postRun(ex.cmd, args, err) } if err != nil { @@ -81,7 +74,6 @@ func (ex *midcobraExecutable) Execute(ctx context.Context, args []string) int { var exitErr *exec.ExitError var userExecErr *usererr.ExitError if errors.As(err, &userExecErr) { - ux.Ferror(ex.cmd.ErrOrStderr(), userExecErr.Error()+"\n") return userExecErr.ExitCode() } if errors.As(err, &exitErr) { diff --git a/internal/boxcli/midcobra/telemetry.go b/internal/boxcli/midcobra/telemetry.go index f5805303da3..aefe6de94c9 100644 --- a/internal/boxcli/midcobra/telemetry.go +++ b/internal/boxcli/midcobra/telemetry.go @@ -8,10 +8,12 @@ import ( "runtime/trace" "sort" + "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" "go.jetpack.io/devbox" "go.jetpack.io/devbox/internal/boxcli/featureflag" + "go.jetpack.io/devbox/internal/boxcli/usererr" "go.jetpack.io/devbox/internal/envir" "go.jetpack.io/devbox/internal/impl/devopt" "go.jetpack.io/devbox/internal/telemetry" @@ -40,6 +42,11 @@ func (m *telemetryMiddleware) postRun(cmd *cobra.Command, args []string, runErr defer trace.StartRegion(cmd.Context(), "telemetryPostRun").End() defer telemetry.Stop() + var userExecErr *usererr.ExitError + if errors.As(runErr, &userExecErr) { + return + } + meta := telemetry.Metadata{ FeatureFlags: featureflag.All(), CloudRegion: os.Getenv(envir.DevboxRegion),