cli icon indicating copy to clipboard operation
cli copied to clipboard

feat: better error messages on malformed option value

Open phm07 opened this issue 1 year ago • 1 comments

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.

phm07 avatar Jun 27 '24 11:06 phm07

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.

Files Patch % Lines
internal/state/state.go 0.00% 24 Missing :warning:
internal/state/config/options.go 0.00% 16 Missing :warning:
internal/state/config/config.go 0.00% 6 Missing :warning:
internal/cmd/server/create.go 0.00% 3 Missing :warning:
internal/state/helpers.go 0.00% 3 Missing :warning:
internal/cmd/base/create.go 33.33% 1 Missing and 1 partial :warning:
internal/cmd/config/get.go 33.33% 1 Missing and 1 partial :warning:
internal/cmd/config/list.go 33.33% 1 Missing and 1 partial :warning:
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.

codecov[bot] avatar Jun 27 '24 11:06 codecov[bot]

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.

phm07 avatar Jul 03 '24 08:07 phm07

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.

apricote avatar Jul 03 '24 12:07 apricote