I have developed a vendetta against poor error messages. I have discovered that validating input like: function isValid(input: string): boolean; Is almost always bad. function getInvalidRange(input: string): undefined | [number, number]; Is way better.
-
Show this thread
-
What does that actually mean? Actually pointing to the specific range and location of invalid input rather than "there is an error in here somewhere".
1 reply 0 retweets 5 likesShow this thread -
Rome ingests package.json files and performs some normalization and validation. One of the fields is name. When you use a package.json name in npm or yarn that is invalid, it will just yell at you. Rome points to the exact location with some possible hints. Examples:
1 reply 0 retweets 4 likesShow this thread -
2 replies 0 retweets 16 likesShow this thread -
Replying to @sebmck
Curious to see how you keep these organized and maintainable. It feels like a *lot* of highly specific code maybe?
1 reply 0 retweets 0 likes -
Replying to @tmdpw
Not really. You queue up errors, always recovering from them by normalizing input etc. Then you have a boundary where you either dump the errors and stop, or write the normalized values somewhere when there's a --fix flag. Easily abstracted.
1 reply 0 retweets 0 likes -
Replying to @sebmck
No, I get that. My question was more around the multitude of possible errors. I imagine there's a separate module for every single test, so how will maintainers know that the validator they want to add exists already? Documentation discipline? Kinda reminds me of ESLint rules.
1 reply 0 retweets 0 likes -
Replying to @tmdpw
The validation and normalization is the same code. I don't really understand the question. There isnt some special set of validators.
1 reply 0 retweets 0 likes -
Replying to @sebmck
I mean "Redundant @ in org name" is one highly specific assertion. I assume there are going to be *tons* like that soon, so my concern is around organizing them and keeping them discoverable. To be clear, I'm totally not saying specificity is a bad thing.
1 reply 0 retweets 0 likes -
Replying to @tmdpw
The validation rules aren't in separate files or even functions. The validation and normalization code is the same and everything is collocated. This is a weird case because it deals with offsets and uses a 0/1-indexed safe library.https://gist.github.com/sebmck/d601cf29070212a4b75862c9e3e0247b …
2 replies 0 retweets 0 likes
Another example. Validating and normalizing the repository field. The type-safe abstractions allow meaningful errors to be generated without custom validation code.pic.twitter.com/gZfH8kkkbz
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 