-
Notifications
You must be signed in to change notification settings - Fork 79
Strict toml marshalling #252
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
Strict toml marshalling #252
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces strict TOML marshalling to prevent users from providing invalid keys and improves error reporting by printing detailed error information. Key changes include updating the signature of GetConfig to return error details, replacing toml.Unmarshal with a manually configured Decoder using DisallowUnknownFields, and altering error handling logic in seshcli/seshcli.go to print error details when available.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| seshcli/seshcli.go | Updates error handling to accommodate new GetConfig signature changes. |
| configurator/configurator.go | Implements strict TOML decoding with detailed error reporting and modifies function signatures accordingly. |
To prevent runtime errors Co-authored-by: Copilot <[email protected]>
randomdude16671
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems ok to me. My apologies for the errors, this is my firet time sending a PR
randomdude16671
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My apologies for the errors, its first time sending a PR
joshmedeski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried testing this PR and I immediately got this error
couldn't unmarshal config file: "strict mode: fields in the document are missing in the target struct"
panic: couldn't unmarshal config file: "strict mode: fields in the document are missing in the target struct"
goroutine 1 [running]:
github.com/joshmedeski/sesh/v2/seshcli.App({_, _})
/Users/joshmedeski/c/sesh/review/seshcli/seshcli.go:57 +0x180c
main.main()
/Users/joshmedeski/c/sesh/review/main.go:23 +0x154
A couple of thoughts:
-
Error visibility: The current error message doesn't indicate which specific field(s) are causing the issue. Could we enhance the error to show exactly what's missing?
-
User experience: Having all sesh commands crash due to config validation feels harsh for the user experience. What would you think about adding a dedicated
sesh config validatecommand instead? This would let users explicitly check their config when needed, while allowing other commands to continue working. -
Default behavior: I'm curious about the reasoning behind making strict mode the default. Could you share your thoughts on this design choice?
Looking forward to your perspective on these points!
|
Thank you for the review. I didn't get this error on my config because its really basic I presume. I like preferred strict mode by default as I feel aligns more with the TOML file type's nature of being only used of configuration purposes. And I think a |
I understand what you mean here but since this is a personal configuration for someone's workflow I would prefer to avoid defaulting to strict mode. This will potentially cause sesh to crash for a lot of users and would force them to have to fix their config before they can start using sesh again. So, I'd rather this be an option that a user can opt-into, rather than changing the default behavior: strict_mode = trueI recommend keeping the current function as-is and adding a new function that can get the config in a strict way. If you have trouble getting the CLI command working don't worry about it and we can merge the core idea here and I can iterate on it. |
|
Thanks, I'll be working on it! |
…r to the best of my ability
|
Update: right now, it works pretty well and I used your idea and it works very well, This new field: [evaluation]
strict = true enables strict mode evaluation, here in evaluation, there can be more options but I can't think of anything that can be put there. |
|
Great, please re-request a review when you're all done. There's no need to be organized with your commit messages. I will do a squash and merge on the PR. |
|
Everything's looking good from my side! Thanks for reviewing my changes patiently and I apologize for any previous errors I might have made. Marking them as ready-for-review now! |
joshmedeski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start here, just a few suggestions.
|
How's progress going on this? Let me know when it's ready for another review. |
|
Yep! This is actually complete in my opinion. Sorry for the late response, was held up in some work. But just one heads up: there's a single |
This prevents users from putting in invalid keys. I also made it print details of the error if the error doesn't result to nil and same with the details. This was done by not using the
toml.Unmarshalalias and creating a Decoder manually with a strings.reader(file)as the argument and enabling strict marshalling to the Decoder,