Skip to content

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

@kayrus

Description

@kayrus

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

"unexpected state '%s', wanted target '%s'. last error: %s",

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions