fix(server): Return nil
instead of "<nil>"
with IPv4/IPv6 disabled
#723
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why:
"<nil>"
isn't very easy to work with in terraform. e.g. there are functions to work with null or the empty string (""), likecompact()
orcoalesce()
, but nothing exists to handle"<nil>"
natively, making it an odd one and requiring specific custom filtering constructs to work with it."<nil>"
is a pretty common thing to return in golang, with tens of usages even in the main repo[1] but HCL is not golanghcloud-go has a very nice IsUnspecified()[1] function to detect if the API returned an unspecified IP address and a quick check says that the hcloud cli command uses it to provide custom text output.
What:
Switch from using unconditionally the output of net.IP.String() function, which returns
"<nil>"
[2] if the IP has length 0, to a conditional usage of the function, setting the address to nil otherwise.Setting the entire struct to nil apparently locally appeases unit tests just fine and even works in some, very simple, scenarios just fine, returning the empty string ("") instead of
"<nil>"
This is an API breaking change. It might not be desirable to merge and/or require some careful handling depending on how widespread the usage of handling
"<nil>"
is. A quick search on my side, did not find any usages[3], but I might have very well failed.[1] https://github.com/search?q=repo%3Agolang%2Fgo%20%22%3Cnil%3E%22&type=code
[2] https://pkg.go.dev/net#IP.String
[3] https://github.com/search?q=%22%3Cnil%3E%22+language%3AHCL&type=code