-
Notifications
You must be signed in to change notification settings - Fork 232
[Feat] Error handler in streams #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Other ecosystem call it https://doc.rust-lang.org/std/result/enum.Result.html#method.inspect_err Eitherway, fine by me |
In this case, side effects aren't necessarily linked to an error; side effects in this context are any operation that shouldn't affect the flow. Think of a call to an external system (e.g., sending an email) that shouldn't affect the processing of the main flow, and is therefore a side effect. Then |
Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>
Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>
Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>
…into feat/error-handler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 💜
🎯 Context
This PR introduces a new error handling and side-effect model for the
GRPC.Streammodule, covering both unary and streaming flows.The implementation improves safety, consistency, and expressiveness across Flow-based pipelines used in gRPC message processing, ensuring that exceptions, errors, and inconsistent return values are handled uniformly and predictably.
🚀 New Features
🧩 1. effect/2
A new utility function to safely perform side effects within a stream pipeline without modifying the values being processed.
⚙️ 2. map_error/2
Adds a declarative mechanism for mapping or transforming errors (
{:error, reason}) within a stream into structuredGRPC.RPCErrorvalues.Behavior:
This enables localized error recovery and translation, useful for both input validation and unexpected runtime exceptions.
🔄 3. Unified Error Matching and Propagation
All stream operators now use the internal safe_invoke/2 wrapper, which standardizes how functions inside the pipeline behave.
This makes all pipelines exception-safe — any operator can raise or throw, but the stream will continue gracefully with well-defined {:error, reason} items.
💡 4. Integration with run/1 and run_with/3
Both stream finalizers (run/1, run_with/3) have been updated to:
✅ 5. Test Coverage
New and extended tests added in GRPC.StreamTest include:
effect/2: ensures side effects are applied safely and do not affect data flow, even when exceptions occur inside the callback.map_error/2: verifies correct error mapping and recovery.map,flat_map,filter,ask, etc.).:process_not_alive,:timeout) inask/3.🧠 Impact
This refactor:
🔮 Next Steps