snafu
json-spanned-value
snafu | json-spanned-value | |
---|---|---|
2 | 1 | |
1,298 | 9 | |
- | - | |
8.0 | 10.0 | |
3 days ago | over 3 years ago | |
Rust | Rust | |
Apache License 2.0 | GNU General Public License v3.0 or later |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
snafu
-
Modular Errors in Rust
I encourage people to check out my SNAFU crate [1]. I encourage creating many distinct error types (usually enums but also structs) and composing them. So much so that I advocate that you never create one specific error in more than one source location. That means that the collection of error types produces a unique trace through your program, uniquely identifying the source of the error with no runtime cost (compare this to a runtime-collected stacktrace / backtrace).
[1]: https://docs.rs/snafu/
-
Announcing Rust 1.58.0
Yes, all procedural macros are inherently unhygienic. This has even bitten us once before.
json-spanned-value
-
Modular Errors in Rust
> The nonsense end result of that line of logic is that you return a single boolean that corresponds to failure/success, so I assume that's not what you mean.
I frequently find that is all that is necessary, and is exactly the correct solution, not "nonsense" whatsoever. Perhaps even that boolean is overkill: an unrecoverable bug should perhaps instead log and then terminate, producing no error condition for the caller of your library to worry about attempting to recover from whatsoever. Detailed error reporting can be done without obscenely distinct error types, and in fact detailed error reporting frequently benefits from a focus on the task itself instead of trying to structure data to leave the task of actually reporting the error to someone else, and kicking the can down the road.
E.g. for parsing focused errors like this I'd be more interested in pretty printing the source line in question, underlining the error, etc. - I wrote https://github.com/MaulingMonkey/json-spanned-value for helping ease the display of bad JSON data in a manner that integrates with your IDE for ease of fixing said data by jumping directly to the cause.
And then, admittedly, there are times when different errors should be recovered from differently. When the caller might wish to retry an operation after some errors, try a different operation after other, report file+line+range information for yet other errors, etc. - these have very concrete answers to "What do you expect the user of your library to do with this detailed information?" that are not difficult to answer at all.
> Contrast the two error messages:
Both are UTF8 strings without types adding anything obviously useful. A silly demo screenshot of errors that will open the offending document if closed, and navigate to the line/column of said error:
https://github.com/MaulingMonkey/json-spanned-value/blob/mas...
Which operates by immediately dumping the "errors" to terminal without any types involved whatsoever... nor even a boolean branch! Well, a real program might set a boolean so the CLI knows to exit(1) instead of using partially parsed data...
What are some alternatives?
rust - Empowering everyone to build reliable and efficient software.
miette - Fancy extension for std::error::Error with pretty, detailed diagnostic printing.
enum-code - derive(Code) simplifies error handling by providing an easy-to-use enumeration of error codes
deno - A modern runtime for JavaScript and TypeScript.
unsafe-code-guidelines - Forum for discussion about what unsafe code can and can't do
gust - Built in Rust and leveraging Docker, JSON, and SQLite (with future integration of a GraphQL API), 'gust' simplifies the process of preserving your recipes and creating comprehensive grocery shopping lists.