guzba / sunny

JSON in Nim with Go-like field tags.
MIT License
14 stars 0 forks source link

[Suggestion] Use a more precise error than 'CatchableError' #13

Open Luyten-Orion opened 3 months ago

Luyten-Orion commented 3 months ago

Hey there, just a small suggestion that'd be useful, a more precise error like 'SunnyError' would be pretty useful for catching errors during JSON parsing specifically in big 'try-except' blocks

guzba commented 3 months ago

I agree with the suggestion but I've found Nim's exception stuff to really not enable this type of thing. The getCurrentException has no type information, raise e loses all type information, and if you catch TypedException as e you must include all the possibilities for e as of statements else your untyped except e: raise e will turn your proc into {.raises: [Exception].} instead of {.raises: [JsonError].}.

Basically I've found it to not be worth bothering with even though I previously did it in other libraries. Maybe I'll add it later but it seems super low value without better support for actually using the type information in control flow etc.

Luyten-Orion commented 3 months ago

That makes sense, though it does suck Nim's type system is like this