-
Notifications
You must be signed in to change notification settings - Fork 137
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
research in error handling #15
base: master
Are you sure you want to change the base?
Conversation
Two other notes:
|
We could also potentially have a global flag which specifies whether or not to catch errors and log them. |
I keep subconsciously brewing on this :) Also worth noting the Go also sides on the error of manual propagation. |
I haven't had time to check this yet. I'll check it soon and reply. |
No worries, I'd actually like to flesh it out a little more before you give a long thoughtful reply about it. I may change a few things, and I'd like to show some more complex examples. Give me another day or two and I'll add some more stuff here. |
Ok, I just forced pushed my latest research. The commit about the arguments removal is already in another PR I just opened (so that can be merged first and it will go away here). I settled on the following, and personally I'm really happy with it. Any feedback is good.
put(ch, Throw(new Error("this is bad")));
go(function*() {
var x = yield take(ch);
}, { propagate: true }); In the worst case, if you forget to add this flag, you won't be able to catch the error but you will at least see the error, and it would be easy to fix. The running philosophy here is "sane defaults"; you will always see errors but you have options to fine-tune how they are handled. Honestly I think only libraries will use this flag a lot; in application code there may be patterns for using channels to route errors where you don't even need this. Need to use this more though.
csp.setDefaultExceptionHandler(function(err) {
console.log('exception', err);
}); This is much safer than node's So that's the design I came up with after several days of thinking really hard about it. What I love about it is that it's actually pretty simple, and aligns well with the CSP philosophy. Obviously I haven't used it very much yet as it's new, so we can hold off on merging it if you want. I'm going to dive into some projects with this and see how it works out. A few last unresolved things:
|
I think this sounds good! I don't have access to a real computer now. Will On Monday, November 10, 2014, James Long notifications@github.com wrote:
Nguyễn Tuấn Anh |
I think this is the right direction, but we could tweak it after trying it out. I'm going to build an app with this soon and see how it feels. |
(been busy with work, but will write more code with this soon and if I feel comfortable with it I will recommend a merge!) |
Hello @jlongster , any news on this one ? |
Sorry about this. I got sucked in at work and lost context for working on all of this, and holidays came. I'm giving another talk in 3 weeks about this & react so you can be sure that I'm going to start working on js-csp again. |
Another quick update, one of the reasons I haven't been as active is because I've been developing a side project using js-csp. I felt it was critical that I get some experience as a user and not just a developer, and it really has helped. Soon I will start reporting my experiences and some improvements I think we could do (and mainly, finish error handling) |
I like the |
This PR needs rebasing. |
Well, unfortunately I don't use this project much anymore. I still think channels are the best approach, but I can't use them for work and I haven't been doing many side projects. The next one I'll do will probably be in ClojureScript. Sorry, but I just don't have time to contribute here anymore. I'll leave these PRs open unless another maintainer wants to close them. |
I'm not quite happy with this yet, but it shows off one implementation. This is from discussions in #14.
With this you can do:
You would see an error "fail!" pointing at the
take
in the second go block, and the thrown line number asput
in the first one.I also experimented with
takePropagate
, which will mostly be used by libraries:The error passed down
ch
is forwarded to thec
channel from the second go block, and the third go block throws an error.I think a fundamental issue is what you talk about in the last paragraph in #14 (comment): should errors in go blocks crash the whole system or not. Whether they are forwarded, when they are logged, etc are all just semantic details. In my above system without automatic error propagation we could still catch all errors in log them instead of crashing the system. Note that as far as I know core.async for ClojureScript would crash the system.