Detect unhandled promise rejections
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- javascript, ruby
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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>
- Lenguaje dominante
- JavaScript
- Estrellas
- 628
- Forks
- 100
- Merge medio
- 1 d 20 h
- PR fusionados (30 d)
- 2
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rubyjs/mini_racer
-
platform: darwin/x86
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
rubyjs/mini_racer#388 · 4 comentarios ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
rubyjs/mini_racer#376 ·
-
Load script as moduleAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
rubyjs/mini_racer#353 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
rubyjs/mini_racer#346 · 6 comentarios · 1 reacción ·
-
Override `Process._fork`?Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
rubyjs/mini_racer#324 · 1 comentario · 1 reacción ·
Todos los issues de rubyjs/mini_racer
Issues similares
-
area: apple-music area: build-release bug effort: small priority: high
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
ChristianTabor/Argon#32 ·
Los mantenedores suelen responder en 1 día
-
0️⃣ phase/new
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Link Checker ReportAbiertoautomated issue report
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
good first issue tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día