Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't panic when String() is called on nil Value{} #86

Merged
merged 5 commits into from
Jun 21, 2021

Conversation

kmoe
Copy link
Member

@kmoe kmoe commented Jun 11, 2021

While a Value without a typ will not be returned from NewValue except in case of error, Value{} is likely to appear in consumer code from time to time, e.g. in tests, as it is the nil value of the struct.

This PR defines an arbitrary string representation for Value{}. The only non-trivial question here is what it should be.

Backwards-compatible because this was previously undefined behaviour.

Bonus

This PR also adds lots of tests for Value.String(), which had little test coverage.

kmoe added 3 commits June 11, 2021 16:39
Currently, attempting to call val.String() where val := Value{} results
in a panic.
While a Value without a type will not be returned from NewValue except
in case of error, Value{} is likely to appear in consumer code from time
to time, e.g. in tests, as it is the nil value of the struct. Define an
arbitrary string representation for Value{}.

Backwards-compatible because this was previously undefined behaviour.
@kmoe kmoe requested a review from paddycarver June 11, 2021 15:55
tftypes/value.go Outdated Show resolved Hide resolved
@kmoe kmoe requested a review from paddycarver June 14, 2021 08:18
Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind just adding a changelog entry in .changelog/86.txt?

@paddycarver paddycarver merged commit 9376d73 into main Jun 21, 2021
@paddycarver paddycarver deleted the dont-panic-nil-value-string branch June 21, 2021 17:53
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants