Detect unhandled promise rejections
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, ruby
Direzione di ricerca
The issue points to V8's SetPromiseRejectCallback and PromiseRejectMessage; start by reading those API definitions and locating how mini_racer connects V8 callbacks to Ruby exceptions. The example shows the missed rejection and the expected error behavior, while the issue leaves the default behavior and configurability undecided. Done means unhandled rejections are reported to Ruby, with the handling behavior defined.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
When working with promises, one important aspect of them is that an unhandled rejected promise is an error. However, V8 will drop notifications by default.
I think that mini_racer should consider this an error and raise an exception, though possibly it should be configurable how these are handled (e.g. via a callback where the user can decide to re-raise?).
To do so, it's necessary to register for unhandled promise rejections via SetPromiseRejectCallback.
The callback will receive a PromiseRejectMessage that should probably (by default) raise a exception in ruby, although I suppose it could be configurable.
Comparisons for reference:
Running this code:
var x = async () => { throw "failure"; };
var y = async () => { x() /* ignore the rejected result */ };
y().then(() => console.log("done")).catch(e => console.log(e));
In node:
> var x = async () => { throw "failure"; }; var y = async () => { x() /* ignore the rejected result */ }; y().then(() => console.log("done")).catch(e => console.log(e));
Promise {
<pending>,
domain:
Domain {
domain: null,
_events:
{ removeListener: [Function: updateExceptionCapture],
newListener: [Function: updateExceptionCapture],
error: [Function: debugDomainError] },
_eventsCount: 3,
_maxListeners: undefined,
members: [] } }
> done
(node:83056) UnhandledPromiseRejectionWarning: failure
(node:83056) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
In chrome:
var x = async () => { throw "failure"; }; var y = async () => { x() /* ignore the rejected result */ }; y().then(() => console.log("done")).catch(e => console.log(e));
VM131:1 done
Promise {<resolved>: undefined}
VM131:1 Uncaught (in promise) failure
In mini_racer:
irb(main):001:0> require 'mini_racer'
=> true
irb(main):002:0> vm = MiniRacer::Context.new
=> #<MiniRacer::Context:0x00007ff4350f1438 @functions={}, @timeout=nil, @max_memory=nil, @current_exception=nil, @isolate=#<MiniRacer::Isolate:0x00007ff4350f12f8 @lock=#<Thread::Mutex:0x00007ff4350f12a8>>, @disposed=false, @callback_mutex=#<Thread::Mutex:0x00007ff4350f1280>, @callback_running=false, @thread_raise_called=false, @eval_thread=nil>
irb(main):003:0> vm.attach('console.log', proc{ |*args| puts('LOG> ' + args.map(&:to_s).join(' ')) })
=> #<MiniRacer::Context::ExternalFunction:0x00007ff43602b1b0 @name="log", @callback=#<Proc:0x00007ff43602b200@/usr/local/lib/ruby/gems/2.5.0/gems/mini_racer-0.1.15/lib/mini_racer.rb:201 (lambda)>, @parent=#<MiniRacer::Context:0x00007ff4350f1438 @functions={"console.log"=>#<MiniRacer::Context::ExternalFunction:0x00007ff43602b1b0 ...>}, @timeout=nil, @max_memory=nil, @current_exception=nil, @isolate=#<MiniRacer::Isolate:0x00007ff4350f12f8 @lock=#<Thread::Mutex:0x00007ff4350f12a8>>, @disposed=false, @callback_mutex=#<Thread::Mutex:0x00007ff4350f1280>, @callback_running=false, @thread_raise_called=false, @eval_thread=nil>, @parent_object_eval="if (typeof console === 'undefined') { console = {} };\nconsole;", @parent_object="console">
irb(main):004:0> vm.eval('var x = async () => { throw "failure"; }; var y = async () => { x() /* ignore the rejected result */ }; y().then(() => console.log("done")).catch(e => console.log(e));')
LOG> done
=> {}
irb(main):005:0>
- Lingua principale
- JavaScript
- Stelle
- 628
- Fork
- 100
- Merge medio
- 1g 20h
- PR unite (30g)
- 2
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rubyjs/mini_racer
-
bug/crash platform: linux/x86
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
rubyjs/mini_racer#422 · 10 commenti ·
-
platform: darwin/x86
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
rubyjs/mini_racer#388 · 4 commenti ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
rubyjs/mini_racer#376 ·
-
Load script as moduleAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
rubyjs/mini_racer#353 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
rubyjs/mini_racer#346 · 6 commenti · 1 reazione ·
Tutte le issue di rubyjs/mini_racer
Issue simili
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
melodic-software/claude-code-plugins#9619 ·
I maintainer di solito rispondono entro 1 giorno
-
bug Frontend P2-medium UI UX
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 76/100
Deepak3699/Ai_Mentor#427 ·
I maintainer di solito rispondono entro 1 giorno
-
resource.reload() while params is in error switches the resource to 'idle' instead of retryingApertaarea: core
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
venn: a name that starts with set-, union-, text- or style- followed by a letter is a parse errorAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
obsidianmd/pele#65 ·
I maintainer di solito rispondono entro 3 giorni
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
11ty/buildawesome#4407 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno