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

feat: better error messages on malformed option value #798

Merged
merged 4 commits into from
Jul 4, 2024

Conversation

phm07
Copy link
Contributor

@phm07 phm07 commented Jun 27, 2024

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 phm07 added the feature label Jun 27, 2024
@phm07 phm07 self-assigned this Jun 27, 2024
@phm07 phm07 requested a review from a team as a code owner June 27, 2024 11:56
Copy link

codecov bot commented Jun 27, 2024

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@apricote apricote left a comment

Choose a reason for hiding this comment

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

Is there any way we can validate the config once at startup instead of doing this whenever one wants to access an option?

@phm07
Copy link
Contributor Author

phm07 commented Jul 3, 2024

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.

@apricote
Copy link
Member

apricote commented Jul 3, 2024

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.

Copy link
Member

@apricote apricote left a comment

Choose a reason for hiding this comment

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

As much as I would like to see the error handling to be gone, I think we can merge this for now.

@phm07 phm07 merged commit 8c6fec9 into main Jul 4, 2024
5 checks passed
@phm07 phm07 deleted the config-error-handling branch July 4, 2024 08:23
apricote pushed a commit that referenced this pull request Jul 17, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.45.0](v1.44.2...v1.45.0)
(2024-07-17)


### Features

* allow configuring default sort columns for each supported resource
([#795](#795))
([f6877a1](f6877a1))
* better error messages on malformed option value
([#798](#798))
([8c6fec9](8c6fec9))


### Bug Fixes

* **config:** ordering of list option values not preserved
([#805](#805))
([1ac27bf](1ac27bf))
* debug log is truncated if it already exists
([#793](#793))
([c3d3a9f](c3d3a9f))
* **firewall:** wrong wording when firewall is removed from resource
([#812](#812))
([9017a65](9017a65)),
closes [#809](#809)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants