https://pulumi.com logo
Title
c

cool-dress-96114

11/14/2022, 11:04 PM
Hi all, question about
output.ApplyT
. How do you error handle with it in the Golang SDK? I’d rather not panic if I can help it. Docs don’t say a ton https://pkg.go.dev/github.com/pulumi/pulumi/sdk/v3/go/pulumi#OutputState.ApplyT
f

fierce-ability-58936

11/14/2022, 11:24 PM
Do you mean not panic when you do type assertion like
intOutput := stringOutput.ApplyT(func(v string) int {
    return len(v)
}).(pulumi.IntOutput)
or something else?
c

cool-dress-96114

11/15/2022, 12:25 AM
kiiiinda.
intOutput := stringOutput.ApplyT(func(v string) int {
    i, err := foo(v)
    if err != nil {
        // handle this err somehow
    }
    return len(i)
}).(pulumi.IntOutput)
something like that is what i’m looking for
how do i handle the err at the outer layer if the subsequent foo(v) call errs
b

billowy-army-68599

11/15/2022, 1:16 AM
you can just return an error from the internal func:
intOutput := stringOutput.ApplyT(func(v string) (int, error) {
    i, err := foo(v)
    if err != nil {
        // handle this err somehow
    }
    return len(i)
}).(pulumi.IntOutput)
c

cool-dress-96114

11/15/2022, 4:19 PM
Ah, I think the problem is I was returning an error as the first and only arg. didn’t realize that part of the output interface was error
thanks @billowy-army-68599!