JavaScript

Topic: Anything JavaScript, ECMAScript including Node, React, ...
Knu
Dec 17, 2018 05:01
In fact it's quite useful when you want to abort a stream.
Knu
Dec 17, 2018 05:00
@david it's not limited to the clone method nor to Chrome.
Knu
Dec 17, 2018 04:48
But browsers have bugs.
Knu
Dec 17, 2018 04:48
Well he's probably right spec wise.
Knu
Dec 17, 2018 04:48
Last time I asked to yutakahirano and he was wrong in the end.
Knu
Dec 17, 2018 04:36
.text() may throw on Chrome
Knu
Dec 17, 2018 04:36
and that means Iv gotta update one of my answers on SO
Knu
Dec 17, 2018 04:35
@david thanks I knew I wasn't crazy
Knu
Dec 17, 2018 04:35
well Iv reproduced it (abort in between 2 then)
Knu
Dec 17, 2018 04:35
but I did it because it may happen
Knu
Dec 17, 2018 04:34
of course it's not right, it's a test
Knu
Dec 17, 2018 03:55
try catch to the rescue, but that's really ugly
Knu
Dec 17, 2018 03:36
it's an AbortError
Knu
Dec 17, 2018 03:36
you can add a breakpoint ull see the error on the clone
Knu
Dec 17, 2018 03:35
pretty much reduced to the minimum
Knu
Dec 17, 2018 03:31
@Meredith just did
Knu
Dec 17, 2018 03:28
Are you seeing something that I don't?
Knu
Dec 17, 2018 03:26
Knu
Dec 17, 2018 03:18
gimme a second Ill create a jsbin
Knu
Dec 17, 2018 03:17
return response.clone();
Knu
Dec 17, 2018 03:17
it can be even simplified to
Knu
Dec 17, 2018 03:17
nothing async like settimeout
Knu
Dec 17, 2018 03:16
> probably throwing an error instead of rejecting
Knu
Dec 17, 2018 03:11
well Iv reduced the function to two lines but yeah a mcve could be useful
Knu
Dec 17, 2018 02:57
I think Iv stumbled on a bug, or maybe that's by design
Knu
Dec 17, 2018 02:56
it shouldn't change anything but who knows
Knu
Dec 17, 2018 02:56
but I removed the second one just to be sure
Knu
Dec 17, 2018 02:56
at first there were 2 things throwing in foo
Knu
Dec 17, 2018 02:55
well
Knu
Dec 17, 2018 02:55
nop
Knu
Dec 17, 2018 02:55
I can even catch the same error using window.addEventListener("unhandledrejection"…
Knu
Dec 17, 2018 02:54
I catch the error, but still Chrome logs "Uncaught (in promise)".
Knu
Dec 17, 2018 02:53
inside foo something throw (response.clone)
Knu
Dec 17, 2018 02:53
my code looks like that
promise.then(foo)
.then(qux, bar)
.catch(baz)
Knu
Dec 17, 2018 02:20
I am dumbfounded, I am catching the error but it still logs that
Knu
Dec 17, 2018 02:19
ever had a "Uncaught (in promise)" in Chrome with an actual catch?
Knu
Dec 16, 2018 23:55
it's logical but idiotic
Knu
Dec 16, 2018 23:54
when using fetch it fires the handler and prevents the consumption of the response
Knu
Dec 16, 2018 23:54
abort after the request has completed, is completely ignored.
Knu
Dec 16, 2018 23:53
The crux of the problem is that the abortion prevents the consumption (for json at least) of the response. That's not something you would have using XHR.
Knu
Dec 16, 2018 23:39
which means I will not end up in the a final catch (if fetch is in progress that's what will happen in my case) because fetch has completed.
Knu
Dec 16, 2018 23:38
@MadaraUchiha Iv just tested and indeed abort may run in between foo and qux on Chrome.
Knu
Dec 16, 2018 23:23
even if the promises are pending the next round will call the microtasks first
Knu
Dec 16, 2018 23:23
since the microtasks have a priority over the macrotasks, I am fine once I leave the function
Knu
Dec 16, 2018 23:21
with an AbortError :)
Knu
Dec 16, 2018 23:21
in that case if you call .json on the response it would throw
Knu
Dec 16, 2018 23:20
the promise is not consumed, but the request was aborted
Knu
Dec 16, 2018 23:20
nop you didn't get what I was saying
Knu
Dec 16, 2018 23:19
e.g. using .json()
Knu
Dec 16, 2018 23:19
because I won't be able, for example, to consume the response