Skip to content

Commit

Permalink
Add recover for panics from handlers
Browse files Browse the repository at this point in the history
This allows the error to actually propagate back to the client instead
of the ominous "exit code 2" and having to search through the daemon
logs to see what happened.

Signed-off-by: Brian Goff <[email protected]>
  • Loading branch information
cpuguy83 committed Jan 29, 2025
1 parent 2b949b2 commit e14f4b1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion frontend/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,13 @@ func (d *clientWithCustomOpts) CurrentFrontend() (*llb.State, error) {

// Handler returns a [gwclient.BuildFunc] that uses the mux to route requests to appropriate handlers
func (m *BuildMux) Handler(opts ...func(context.Context, gwclient.Client, *BuildMux) error) gwclient.BuildFunc {
return func(ctx context.Context, client gwclient.Client) (*gwclient.Result, error) {
return func(ctx context.Context, client gwclient.Client) (_ *gwclient.Result, retErr error) {
defer func() {
if r := recover(); r != nil {
retErr = errors.Errorf("recovered panic in handler: %+v", r)
}
}()

if !SupportsDiffMerge(client) {
dalec.DisableDiffMerge(true)
}
Expand Down

0 comments on commit e14f4b1

Please sign in to comment.