Comments (11)
I would much prefer a simple {:ok, events}
or {:error, reason}
vs having four different return types @drozzy
Receivers that still want to match on whether there are zero, one, or multiple can still do that with pattern matching but aren't forced to implement 4 different matches if they don't care how many events were returned (e.g. they just process all or none of them)
from commanded.
I'm proposing that the change would be backwards compatible, so you can still choose to return just an event, or list of events. The {:ok, events}
is in addition to what's currently allowed.
Aggregate return value | Events produced |
---|---|
:ok , nil , [] |
none |
event , {:ok, event} |
one event |
events , {:ok, events} |
list of events |
{:error, reason } |
an error occurred |
@astery The with
special form can also sometimes be used to declutter such code.
from commanded.
Recently, I tried to write tests with {:ok, ..}, {:error}, and change my mind about it. Code become cluttered with :ok tuples. With current manner aggregate and their tests are clearer. Adding :ok tuples brings no real benefit except being "idiomatic", but some kind of unneeded complexity which is harder to read.
So I would prefer not to change anything.
from commanded.
What would be the benefit of using {:ok, _}
tuples? Is there an {:error, reason}
case as well?
from commanded.
Using {:ok, events}
and {:error, reason}
tagged tuples would make it consistent with idiomatic Elixir code. Commanded already supports {:error, reason}
.
from commanded.
It's controversial. On one side it's bring a need of code change and extra keystrokes. On over side then I see function returning {:error, _}
, I expect to see {:ok, _}
as success; and if function return struct, I expect it either return nil or throw an error.
I support this.
from commanded.
I was going to suggest something like {:events, [Event]}
, but after thinking about it, the ok/error
combination would be more idiomatic (in fact, I was briefly puzzled by the lack of :ok
when first learning commanded - since I didn't know how to indicate an error
):
:ok
- In the event command was accepted and no events were produced{:ok, event}
- In the event command was accepted and one event was produced.{:ok, events}
- In the event command was accepted and one or more events were produced.{:error, Reason}
- In the event of the command for rejected for a given reason.
I am not a fan of throwing. Let's not resort to that please.
from commanded.
Alternatively, we could use something more semantic instead of ok
and error
, like accepted
and rejected
.
from commanded.
I'd rather leave it as is @slashdotdash, that looks you're asking for confusion later on.
from commanded.
Idiomatic in this case just means more verbose, I don't see the point.
from commanded.
@slashdotdash are we ok to leave the current implmentation as it is?
Or do we need to add those new format?
from commanded.
Related Issues (20)
- warning: redefining module Commanded.Serialization.JsonDecoder.Any HOT 2
- Event number gaplessness required?
- Commanded.aggregate_state does not work when aggregate identity has a prefix HOT 10
- Process manager router option not working
- Lessons learned from performance optimization - an unlikely culprit HOT 3
- no function clause matching in Commanded.Commands.Dispatcher.telemetry_stop/3 HOT 1
- Docs questions
- Stacktrace in event handler error? HOT 2
- Paralelization Strategies in EventHandlers
- Should Commanded.Event.Handler support messages from swarm? HOT 2
- Event retention policies?
- please support multiple commanded application with one eventstore HOT 6
- Process Manager state serialization breaks when using a custom TypeProvider with the JsonSerializer
- `Commanded.ProcessManagers.ProcessManager.identity/0` function returns `nil` in unit tests
- no function clause matching in Commanded.Event.Handler.partition_event/4 HOT 1
- EventstoreDB is sunsetting the TCP protocol HOT 1
- Is it a bad practice for an event handler to depend on a projector completion? HOT 2
- Snapshotting 2 Aggregates having same identity
- Is it possible to log contents of InMemoryEventStore on failed test?
- Ecto Sandbox, Projections and In Memory adapter HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from commanded.