mercari / hcledit

Go package to edit HCL configuration
MIT License
44 stars 13 forks source link

fallbackToRawString issue #124

Closed piggybankwang closed 1 month ago

piggybankwang commented 1 month ago

not fully understand why when fallbackToRawString == true you still throw errors https://github.com/mercari/hcledit/pull/107 then how do we read rawtring properly, we are currently handler error from the caller

ryan-ph commented 1 month ago

@piggybankwang sorry for the late reply.

We return still return the error because it signals that fallback has actually occurred and the caller should treat it as a raw value. hcledit provides the RawVal as a way to distinguish between raw value vs. a normal cty value (normal meaning that the actual value can be read without fallback).

If you know for sure that the value you are reading needs to fallback to the raw string, you can ignore the error. If you are unsure if the value you are reading needs to fallback, you can check if the error is nil and determine if you need to handle it as a raw string or now.