Marcono1234 / struson

Streaming JSON reader and writer written in Rust
https://crates.io/crates/struson
Apache License 2.0
59 stars 6 forks source link

[simple-api] Improve handling of discarded errors #55

Closed Marcono1234 closed 6 months ago

Marcono1234 commented 6 months ago

Problem solved by the enhancement

The goal of the Simple API (both reader and writer) is to make usage easier and reduce risk of panics. However, when a closure / function provided by the user by accident discards an error from reader or writer without propagating it, this can still lead to incorrect behavior and possibly panics. That could for example happen when users ignore or overlook compiler warnings about unused results, or use methods such as Result::map_or or Result::or_else on the result of reader or writer methods.

Enhancement description

If possible the reader and writer should track whether an error occurred, and prevent any subsequent explicit and implicit usage (e.g. when the method performs additional implicit calls to the underlying JsonReader).

Potential implementations:

When a reader or writer method is used but a previous error exists, the implementation could:

Additionally the documentation for SimpleJsonReader and SimpleJsonWriter should make it clearer that errors from the reader or writer inside closures / functions must be propagated, ideally with the ? operator.

Alternatives / workarounds

Only adjust documentation