Conversation
Ethiraric
left a comment
There was a problem hiding this comment.
Most of the changes I asked are just related to making the enum Copy.
I trust you on the naming. I'll try and keep in mind to make a pass on it before the next release, but I don't want to block this PR that long.
I wonder however how relevant it is to be this specific in errors. I probably would have kept the code limited to a list akin to
SyntaxError (maybe IndentError?)
DuplicateDirective
DirectiveError
EncodingError
UnexpectedEoF
UndeclaredAnchor
|
|
||
| if string.is_empty() { | ||
| return Err(ScanError::new_str(start_mark, "while scanning an anchor or alias, did not find expected alphabetic or numeric character")); | ||
| return Err(ScanError::new_str(start_mark, "while scanning an anchor or alias, did not find expected alphabetic or numeric character", ScanErrorCode::AlnumCharacterExpected)); |
There was a problem hiding this comment.
This might need formatting. Have you run cargo fmt?
There was a problem hiding this comment.
If I change the import order cargo fmtcorrects it.
But something like long lines stays unchanged, at least for me.
I don't know why, there's no rustfmt.toml or .editorconfig.
|
I working on a multilingual app and one of the native languages I'd like to have at start will be Polish. If we keep list too broad and unsorted, it could be a mess, which I suppose @Ethiraric try to solve by proposing less errors. On the other hand, if we keep it too small, a user can't do much from "syntax error" translated on the target language. To keep both of worlds I propose to split by categories proposed by @Ethiraric, but keep them rich by providing sub-codes to keep errors meaningful. And all keep these enums non-exhaustive to add more in the future. What do you @Ethiraric and @davvid think? |
|
Oh, my bad. I mistakenly placed myself from the point of view of It would make sense to have categories still. I thought there was some |
|
What would I thought on something simpler like following: enum ScanErrorCode {
InvalidUTF8(InvalidUTF8Code),
// ...
}
enum InvalidUTF8Code {
IncorrectLeadingUTF8Byte,
// ...
} |
|
Your suggestion would add the need of many smaller enums. A single match would just coerce multiple variants into a single category : match code {
InvalidUTF8 | InvalidBOM => Encoding,
UnexpectedTab | TooManySpaces => Indentation
...
} |
|
I propose following error structure: ScanErrorCode -> ~> actual error In this way a person who handle this can stop:
Advantages are:
As I understand (please correct me if I wrong), you propose to have a one big enum and call a function to get a category. This isn't cheap and isn't free. |
|
@Ethiraric one thing I haven't address in my previous comment is amount of categories. There won't be many categories in the first place and category amount won't grow. Additionally, I doubt that classification would need to be ever changed |
|
it's not my project, but I've tried to make it more readable, because such enums are very hard to ever change. you can decide whatever you see fit. |
Co-authored-by: Ethiraric <ethiraric@gmail.com>
Closes #29