-
Notifications
You must be signed in to change notification settings - Fork 219
chore: improve error handling for templates #1687
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,54 @@ | ||
| package builderrors | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
|
|
||
| "github.com/e2b-dev/infra/packages/orchestrator/internal/template/build/phases" | ||
| template_manager "github.com/e2b-dev/infra/packages/shared/pkg/grpc/template-manager" | ||
| ) | ||
|
|
||
| const ( | ||
| InternalErrorMessage = "An internal error occurred. Please try again or contact support with the build ID." | ||
| ) | ||
|
|
||
| // User errors | ||
| var ( | ||
| CanceledError = errors.New("build was cancelled") | ||
|
Check failure on line 17 in packages/orchestrator/internal/template/build/builderrors/errors.go
|
||
| TimeoutError = errors.New("build timed out") | ||
|
Check failure on line 18 in packages/orchestrator/internal/template/build/builderrors/errors.go
|
||
| ) | ||
|
|
||
| // IsUserError returns true if the error is a user error (i.e., a PhaseBuildError). | ||
| // User errors are caused by the user's configuration and should be shown to them. | ||
| func IsUserError(err error) bool { | ||
| return phases.UnwrapPhaseBuildError(err) != nil | ||
| } | ||
|
|
||
| // WrapCanceledAsUserError wraps context.Canceled as a user error if no user error already exists. | ||
| // This ensures that user-initiated cancellations are tracked as user errors in metrics. | ||
| func WrapCanceledAsUserError(err error) error { | ||
| if err == nil { | ||
| return nil | ||
| } | ||
|
|
||
| // If it's already a user error, return as-is | ||
| if IsUserError(err) { | ||
| return err | ||
| } | ||
|
|
||
| // If it's a canceled context, wrap it as a user error | ||
| if errors.Is(err, context.Canceled) { | ||
| return phases.NewPhaseBuildError(phases.PhaseMeta{}, CanceledError) | ||
| } | ||
|
|
||
| // If it's a timeout context, wrap it as a user error | ||
| if errors.Is(err, context.DeadlineExceeded) { | ||
| return phases.NewPhaseBuildError(phases.PhaseMeta{}, TimeoutError) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Internal errors masked when context is also canceledMedium Severity When an internal error occurs and the context is also canceled, the defer in Additional Locations (1) |
||
|
|
||
| return err | ||
| } | ||
|
|
||
| func UnwrapUserError(err error) *template_manager.TemplateBuildStatusReason { | ||
| phaseBuildError := phases.UnwrapPhaseBuildError(err) | ||
| if phaseBuildError != nil { | ||
|
|
@@ -15,6 +59,6 @@ | |
| } | ||
|
|
||
| return &template_manager.TemplateBuildStatusReason{ | ||
| Message: err.Error(), | ||
| Message: InternalErrorMessage, | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.