←back to thread

203 points dahlia | 1 comments | | HN request time: 0.232s | source
Show context
12_throw_away ◴[] No.45154518[source]
I like this advice, and yeah, I always try to make illegal states unrepresentable, possibly even to a fault.

The problem I run into here is - how do you create good error messages when you do this? If the user has passed you input with multiple problems, how do you build a list of everything that's wrong with it if the parser crashes out halfway through?

replies(6): >>45154618 #>>45154627 #>>45155518 #>>45155610 #>>45155934 #>>45156178 #
ambicapter ◴[] No.45154618[source]
Most validation libraries worth their salt give you options to deal with this sort of thing? They'll hand you an aggregate error with an 'errors' array, or they'll let you write an error message "prettify-er" to make a particular validation error easier to read.
replies(2): >>45154990 #>>45155372 #
1. Thaxll ◴[] No.45154990[source]
This work if all errors are self contained, stoping at the first one is fine too.