Hi all, question about `output.ApplyT`. How do you...
# general
c
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
Do you mean not panic when you do type assertion like
Copy code
intOutput := stringOutput.ApplyT(func(v string) int {
    return len(v)
}).(pulumi.IntOutput)
or something else?
c
kiiiinda.
Copy code
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
you can just return an error from the internal func:
Copy code
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
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!