feat: better error messages on malformed option value
Previously, if an option was configured with the wrong type (e.g. string was configured with an int value) or other parsing errors like malformed duration/boolean values occured, Option[T].Get() would panic. It now returns an error that can properly be displayed to the user and falls back to the default value.
Codecov Report
Attention: Patch coverage is 24.67532% with 58 lines in your changes missing coverage. Please review.
Project coverage is 59.60%. Comparing base (
c0cb16b) to head (084c746). Report is 3 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #798 +/- ##
==========================================
- Coverage 59.68% 59.60% -0.08%
==========================================
Files 210 210
Lines 7639 7684 +45
==========================================
+ Hits 4559 4580 +21
- Misses 2437 2459 +22
- Partials 643 645 +2
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Is there any way we can validate the config once at startup instead of doing this whenever one wants to access an option?
We could run this method one time for each option on startup (or on the first Get() call if the cache is not yet initialized) and then cache the result. Then we would only need a static type cast after that for accessing the value.
However, it would make the code a lot more complex and the performance difference would not be noticeable (probably not even measurable), so I don't know if it's worth it.
We could run this method one time for each option on startup (or on the first Get() call if the cache is not yet initialized) and then cache the result. Then we would only need a static type cast after that for accessing the value. However, it would make the code a lot more complex and the performance difference would not be noticeable (probably not even measurable), so I don't know if it's worth it.
My primary concern is not the performance, but rather that it is very annoying to check for an error every time you access the config.