#How to make container panic when it errors

1 messages · Page 1 of 1 (latest)

grave plaza
#

Hey, we ended up writing a function like this:

    ctr = ctr.WithExec(exec)
    c, err := ctr.ExitCode(ctx)

    if err != nil || c != 0 {
        panic(fmt.Sprintf("error when executing %v: %v", exec, err))
    }

    return ctr
}```
I wonder if there's any Dagger-native way of doing this? We had a container on which we executed quite a few commands and one of the first ones had error which we didn't notice early enough and ended up in troubles.
north coyote
#

I don't think we've got something like that, but you could write a helper function if that is what you want:

type DaggerFallible[T any] interface {
    ExitCode(ctx context.Context) (T, error)
}
func FailOnError[T any](ctx context.Context, c DaggerFallible[T]) T {
   t, err := c.ExitCode(ctx)
   if err != nil {
       panic(fmt.Errorf("dagger encountered a non-zero error code: %v", err))
   }

   return t
}

This is pretty much the same as yours though a little more generalized.

As far as I can tell there isn't anything like that in dagger itself.