what’s the intended pattern for the error-handling...
# golang
c
what’s the intended pattern for the error-handling form of
ApplyT
? i’m naively trying to achieve something like the following:
Copy code
policyDocument, err := saml.Arn.ApplyT(func(arn string) (*iam.GetPolicyDocumentResult, error) {
  return iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
    Statements: []iam.GetPolicyDocumentStatement{
      {
        Principals: []iam.GetPolicyDocumentStatementPrincipal{
          {
            Type:        "Federated",
            Identifiers: []string{arn},
          },
        },
      },
    },
  })
})
if err != nil {
  return err
}
but of course
ApplyT
only returns a single value of type
internal.Output
. how would i bubble up an error from
iam.GetPolicyDocument
? or perhaps the question is, how should I use
ApplyT
correctly here?
a
If your plan is to fail the program if
err
is non-nil, then you are already using
ApplyT
correctly:
Copy code
policyDocument := saml.Arn.ApplyT(yourFunction)
If you want to handle the error and keep going, you will need to do so inside the `ApplyT`:
Copy code
policyDocument := saml.Arn.ApplyT(func(arn string) (*iam.GetPolicyDocumentResult, error) {
  doc, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
    Statements: []iam.GetPolicyDocumentStatement{
      {
        Principals: []iam.GetPolicyDocumentStatementPrincipal{
          {
            Type:        "Federated",
            Identifiers: []string{arn},
          },
        },
      },
    },
    if err != nil {
      return defaultDocument(arn)
     }
     return doc
  })
})
The first option is more common in Pulumi programs, but both are available.