Skip to content

[errors] Show better errors when user script errors out and fix poetry plugin #1511

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

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 1 addition & 8 deletions internal/boxcli/midcobra/midcobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions internal/boxcli/midcobra/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions plugins/poetry.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"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",
"POETRY_VIRTUALENVS_PATH": "{{.Virtenv}}/.virtualenvs"
},
"shell": {
"init_hook": [
"poetry env use $(command -v python) --quiet --no-interaction"
"poetry env use $(command -v python) --no-interaction"
]
}
}