-
Notifications
You must be signed in to change notification settings - Fork 55
fix: improve invalid slice name error #240
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
fix: improve invalid slice name error #240
Conversation
|
letFunny
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.
Hi! Thank you for taking the time to work on this. I agree that we should improve the error messages to some extent to improve the UX. At the same time, writing prose to describe the regular expression might not be ideal, it will always be less precise and too verbose.
Let's see if we can create a message that is short and simple.
internal/setup/yaml.go
Outdated
| match := apacheutil.SnameExp.FindStringSubmatch(sliceName) | ||
| if match == nil { | ||
| return nil, fmt.Errorf("invalid slice name %q in %s", sliceName, pkgPath) | ||
| return nil, fmt.Errorf("invalid slice name %q in %s (slice names must be at least 3 characters long, start with a lowercase letter, and contain only lowercase letters, digits, and hyphens)", sliceName, pkgPath) |
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.
This is not strictly true, the current regular expression doesn't match c-- for example, even though it is 3 characters long, starts with a lowercase letter and contains only lowercase letters and hyphens.
See regexr.com/8gm94.
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.
Thank you @letFunny for the regex link! It makes more sense now! Regex is always tricky. Looking at the regex ^([a-z](?:-?[a-z0-9]){2,})$ more carefully, I agree with you that "must be at least 3 characters" is still imprecise - strings like c-- or d- would fail for reasons beyond just length. I've updated the message to focus on the minimum length requirement since that was the specific confusion reported in issue #158.
However, we need to create a message that is concise and straightforward. What's the most common slice name validation error you've seen reported in community forums or support channels? Is it typically the length issue, or do users frequently encounter other validation failures?
Happy to work with you to update something more meaningful and useful to the user. Cheers.
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.
Hey @gajeshbhat, thank you for making the changes. I agree with you the regex is very tricky and we should focus on the most intuitive requirements. At the same time, there is a balance to strike here, we shouldn't only mention one of the possible errors, let's try to mention all of them.
I had the chance of brainstorming about improving the UX today with @niemeyer and we landed on the following error message which is pretty sweet:
invalid slice name %q in %s (start with a-z, len >= 3, only a-z / 0-9 / -)
It captures all the common errors and, at the same time, it follows the style of your original PR of being easy to read. What do you think? Can we use this one?
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.
Thank you @letFunny, for brainstorming on this. I like the concise format you have proposed, but don't you think: "only a-z / 0-9 / -" would mislead the users since strings like config- or ab- contain only those characters but still fail because hyphens must be followed by a letter/digit? How about something like:
invalid slice name %q in %s (start with a-z, len >= 3, use a-z/0-9 (- allowed between chars) )
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 agree that this doesn't specify all the rules. At the same time it is hard to strike a balance between being precise and being helpful. If we wanted to be precise I would print the regex directly or put it in the documentation, that leaves no room for interpretation. By adding more rules you complicate it a bit because what does "between chars" mean, it is a bit ambiguous.
I would say let's keep the one I posted for now and we can always come back to this if there is a need for more descriptive message. If that is the case then documenting it more thoroughly in the reference documentation seems like an even better idea. Right now there is a paragraph there but it is not very precise: https://documentation.ubuntu.com/chisel/en/latest/reference/chisel-releases/slice-definitions/.
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 see your point about the precision vs. helpfulness trade-off. You're right that "between chars" is also ambiguous, and trying to be perfectly precise in an error message would make it unwieldy. I've updated the PR with your suggested message. Thank you for helping improve this PR. I have contributed to Canonical projects before, hence the CLA check should pass once approved. Please let me know if you have any questions. Cheers.
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.
On a side note, I went ahead and created an Issue #241 to update the documentation. I am happy to pick this up sometime later.
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.
We had the same idea about the documentation, hours before your issue I created a PR to fix it :)
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.
Thank you for contributing
ac9f29a to
62e6572
Compare
- Add improved error message - Add unit test to verify the improved error message Fixes canonical#158
62e6572 to
b3d87b3
Compare
letFunny
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.
Thank you for looking into improving the UX @gajeshbhat! LGTM
Thank you for the review @niemeyer . Appreciate you taking the time. |
This PR improves the error message for invalid slice names to provide clearer guidance to users about the validation requirements, as requested in #158.
Changes
internal/setup/yaml.goto clarify that slice names must be at least 3 characters longBefore
error: invalid slice name cc in
slices/base-distroless.yamlAfter
error: invalid slice name cc in
slices/base-distroless.yaml(slice names must be at least 3 characters long, start with a lowercase letter, and contain only lowercase letters, digits, and hyphens)Testing
Fixes #158