question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to handle errors thrown from defineCommand / defineEvent handlers?

See original GitHub issue

Hi! For example:

export = domain.defineEvent({},  (data, aggregate) => {
    aggregate.set('balance', data.balance);
    aggregate.set('value', data.value);

    throw new FakeError(); // unhandled, something went wrong or TypeError
});

how to handle such type of errors?

Approach listed below doesn’t help.

    async handle(data: object) {
        return new Promise((resolve, reject) => {
            try {
                this.domain.handle(data, (err) => {
                    if (err) {
                        reject(err);
                    } else {
                        resolve();
                    }
                });
            } catch (e) {
                reject(e);
            }
        });
    }

This problem is similar for defineViewBuilder of eventdenormalizer. Can’t catch errors there too.

another a little question: Why custom command handler is so bad?

Command Handler (Be careful!!!)
Is your use case not solvable without a custom command handling? Sagas? Micro-Services?

what if I need to make external operation like 3rd party API http call and generate event with resulted data without saving to eventstore. This event then can be handled by sagas to generate command to update required aggregate.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
imissyousocommented, Jan 31, 2020

Always happy for a PR.

currently we are at stage of investigating and collecting potential issues before the real start of development. As soon as we will do it wait PR from us 😃

1reaction
adraicommented, Jan 31, 2020

Always happy for a PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to catch an exception inside an event listener?
on handler is located inside a try..catch block, the function is executed asynchronously and therefore any error thrown inside this function is ...
Read more >
Exceptions thrown from within event handlers crashes the app
Current behavior. Exception thrown from within EventHandlers craches the app. Expected behavior. A way to handle and don't crash the app.
Read more >
Window: error event - Web APIs - MDN Web Docs - Mozilla
The error being thrown. Usually an Error object. Note: These parameter names are observable with an HTML event handler attribute, where the ...
Read more >
Error Handling — The Swift Programming Language (Swift 5.7)
When a function throws an error, it changes the flow of your program, so it's important that you can quickly identify places in...
Read more >
Handle errors in ASP.NET Core | Microsoft Learn
If the alternate pipeline throws an exception of its own, Exception Handling Middleware rethrows the original exception.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found