rapid-kangaroo-18476
07/17/2025, 6:29 PMpanic
, how can I handle errors that my ApplyT
function returns? I'd like my pulumi preview
or pulumi up
to exit upon error.
I've read through docs and looked through source code and haven't found a solid answer. I'd like the following pseudocode to fail pulumi preview
or pulumi up
but it currently keeps running after I return an error. I would expect pulumi to detect that the OutputState.err
field contains an error and abort the rest of the deployment. However, it just continues. Since this field is private, I have no way of extracting it either. The only option I've found is to panic but this doesn't actually reference the returned error (I'd need to explicitly panic within my function) so it seems like there was some intended way to use the returned error. Either the returned error is unused or I'm not looking in the right place. Any help would be appreciated!
I expect this to bubble up the error but it doesn't:
output := someStringOutput.ApplyT(func(someString string) (string, error) {
return "", fmt.Errorf("always error")
})
If I panicked instead, then the returned error is useless (so no need to return an error, panic short-circuits the return anyway):
output := someStringOutput.ApplyT(func(someString string) string {
panic("always panic")
})
little-plumber-23857
07/22/2025, 7:35 AMerr
reference before the apply and save the output in this var. So you can access it after the apply is done. But then you need to wait and it can be a blocker for your code.rapid-kangaroo-18476
07/22/2025, 3:54 PMlittle-plumber-23857
07/22/2025, 4:09 PMrapid-kangaroo-18476
07/22/2025, 4:12 PMbright-garden-52526
07/29/2025, 5:32 PMbright-garden-52526
07/29/2025, 5:35 PMvar err error
wait := make(chan struct{}, 1)
output := someStringOutput.ApplyT(func(someString string) (string) {
defer close(wait)
o, err = something()
return o
}).(pulumi.StringOutput)
<-wait
if err != nil {
return err
}
bright-garden-52526
07/29/2025, 5:35 PM