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
[rstream] Error handling bug/inconsistency? #276
Comments
Thanks for the effort in documenting your troubles - and am sorry you're having them in the first place. Will take a closer look ASAP, but probably will take me until the weekend... All I can tell you right now is that I've never used (or seen) the kind of "scoped error" attachment you're showing here and it seems wrong to me. I.e. a subscriber object being passed to |
One thing you could try (or we could add) is something along these lines: const withErrorLogging = (next) => ({ next, error(e) { console.log(e); } });
reactive(10).subscribe(withErrorLogging((x) => { throw new Error(`bad: ${x}`); }));
// Error: bad: 10 The cases with |
Cheers, no rush. Thought it was best to document.. I realise it was more my use of the error handler after the subscribe/post-factum that was the problem. And had been blindly using the 'scoped' handlers for error handling after seeing it here #125. I will definitely stick to subscriber objects from now on! Not sure if there is anyway to warn / throw in those cases if no known handler exists.. Grand work either way!! :) |
I've just committed a change which forces errors to be logged to the console even if a sub doesn't specify an error handler and if the default |
Sounds good! I have dug into the rstream code a lot more since this last brain lapse... I think a lot of my confusion came from
I am now ( hopefully ) more well versed in the nuances of the internals, and have answered all my woes! I was generally trying to follow the idea of using transform() to manipulate the stream and subscribe() when i wanted to create a 'view' of it. And hadn't really realised the transform() op was returning a new subscription - but thinking it was applying at the current scope. Either way, It makes sense to have those two methods, it's just a shame you can't add an error handler at the same time. Either : str.subscribe({
next:()=>{},
error:(err)=>{ throw err}
},comp(
map((etc)=>etc)
)) or str.subscribe(subscription({
next:()=>{},
error:(err)=>{ throw err}
},{
xform: map((etc)=>etc)
})), It's a bit more verbose and i have to add the unnecessary next:()=>, but it gives me error handling - although without the nice transform() naming flow... Not sure if an error handler coule be passed in as a last arg to transform() ( seems a bit ugly ) or may be a default error should be added to the subscription, that gives you a more appropriate error/console message directing you to the transform(). Anyways, I'm thinking out aloud here... I'm sure the logger will do it! :) |
FWIW I'm not too happy/comfortable with the current error handling either, but will think about it some more. The least I should do ASAP is fixing the first arg type for I.e. you only need to use src.subscribe({}, map((x) => x * 11)) //.single xform
src.subscribe({}, comp(map((x)=> x*11), filter((x) => (x%2)>0))); // multiple xforms
src.transform(map((x)=> x*11), filter((x) => (x%2)>0)); // same as above
src.transform(map(...)).transform(filter(...)) // logically the same, but slower, since it creates two chained subscriptions Re: your idea about adding an additional/optional error handler arg - we could add it to the optional options arg, but then only for src.transform(map((x)=> x*11), filter((x) => (x%2)>0), { error: console.warn }); |
BREAKING CHANGE: update ISubscribable contract, remove transducer only version of `.subscribe()`, MUST provide dummy sub w/ transducer OR (better) use `.transform()` instead (which also more clearly communicates intention...) - another breaking change side effect for `.subscribe()`: `next()` handlers MUST be provided now in first arg (child sub), this is NOT because they're mandatory now, but TS won't be able to correctly infer arg types when using `Partial<ISubscriber<T>>` - add `DUMMY` subscriber constant w/ empty `next() {}` - simplify internal `.subscribe()` logic - add `WithErrorHandlerOpts` interface - update `.transform()` & `.map()`: add error handling support
@jamieowen started working on a PR for this, take a look at the expanded commit messages & comments in #279... |
@postspectacular Looks good. Makes a lot more sense like this. When not mixing the 2 methods. Do you think it would be good to have an opts only approach on transform too? src.transform({
xform: map((etc)=>etc),
error:()=>{
}
}); I could then compose reusable transform objects similar to how i might have for subscriptions. const customTransform = ( mult:number )=> ({
xform: map(x=>x*mult),
error:()=>{
}
})
src1.transform(customTransform(10));
src2.transform(customTransform(42)); For context : I am experimenting with a pipeline style setup for manipulating geometry/buffers on RAF and create 'render subscriptions': const renderLines = ()=>{
// setup
return {
next:()=>{
// render
}
}
}
str.subscribe(renderLines());
str.subscribe(renderPoints()) I had began using a similar approach for reusable transforms. ( But obviously using the current subscribe() method + xform obj ) |
@jamieowen can this issue be closed now that #281 is in place or still things unclear/unhappy? |
@postspectacular yep, been meaning to reply to this. All really great stuff! Looking forward to updating to the new version. Thanks! FYI, I did finish those photoshop blend modes as well actually. Will get back to them soon.. :) |
Hi,
This might be less of a bug, but more inconsistency / confusion from an api point of view.
That is now i've learnt the errors of my ways at least - the hard way! )
I thought i'd mention either way...
But when using the reactive() helper and attaching scoped error handlers ( see below ) , any initial errors on startup fail silently and become difficult to track down unless attaching a logger. The api kind of encourages you down a few confusing rabbit holes...
By error handlers i mean :
Here's some cases where errors are handled / or not... ( from code sandbox : https://codesandbox.io/s/blue-cookies-3nk5x?file=/src/index.ts )
I'm not sure if this could be fixed to support the error = ()=> handler on initial error?
Or may be just better to attach error handlers and then call next()
What do you think?
The text was updated successfully, but these errors were encountered: