hashicorp / terraform-plugin-sdk

Terraform Plugin SDK enables building plugins (providers) to manage any service providers or custom in-house solutions
https://developer.hashicorp.com/terraform/plugin
Mozilla Public License 2.0
436 stars 231 forks source link

Don't print `UnexpectedStateError.LastError` when it's nil #1359

Open kayrus opened 3 months ago

kayrus commented 3 months ago

SDK version

...
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0

Use-cases

In case when the retry func faces an unexpected resource status it returns unexpected state 'ACTIVE', wanted target 'DELETED'. last error: %!s(<nil>).

Attempted Solutions

Proposal

There should be more cleaner error report, when LastError is nil: unexpected state 'ACTIVE', wanted target 'DELETED', e.g.

func (e *UnexpectedStateError) Error() string {
        if e.LastError == nil {
                return fmt.Sprintf( 
                        "unexpected state '%s', wanted target '%s'.",
                        e.State,
                        strings.Join(e.ExpectedState, ", "),
                )
        }
        return fmt.Sprintf(
                "unexpected state '%s', wanted target '%s'. last error: %s",
                e.State,
                strings.Join(e.ExpectedState, ", "),
                e.LastError,
        )
}

References

https://github.com/hashicorp/terraform-plugin-sdk/blob/4c604df5f03572d01e7c32777b339519213eb475/helper/retry/error.go#L45

https://github.com/search?q=%22last+error%3A+%25%21s%28%3Cnil%3E%29%22&type=issues