Browse Source

Uncaught exception & promises in Node as well.

Herby Vojčík 3 years ago
parent
commit
2450a3b8e9
3 changed files with 75 additions and 0 deletions
  1. 8 0
      CHANGELOG
  2. 57 0
      lang/src/Platform-Node.js
  3. 10 0
      lang/src/Platform-Node.st

+ 8 - 0
CHANGELOG

@@ -1,3 +1,11 @@
+?? Oct 2020 - Release 0.29.3
+===================================
+
+* Uncaught exceptions / promises now in node platform as well.
+
+Commits: https://lolg.it/amber/amber/commits/0.29.3.
+
+
 19 May 2020 - Release 0.29.2
 ===================================
 

+ 57 - 0
lang/src/Platform-Node.js

@@ -107,6 +107,63 @@ return global;
 }; }),
 $globals.NodePlatform);
 
+$core.addMethod(
+$core.method({
+selector: "initialize",
+protocol: "initialization",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "initialize\x0a\x09process\x0a\x09\x09on: 'uncaughtException'\x0a\x09\x09do: [ :err | ErrorHandler handleError: err. process exit: 1 ];\x0a\x09\x09on: 'unhandledRejection'\x0a\x09\x09do: [ :err | ErrorHandler handleError: err. process exit: 2 ]",
+referencedClasses: ["ErrorHandler"],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["on:do:", "handleError:", "exit:"]
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1;
+$1=process;
+[$recv($1)._on_do_("uncaughtException",(function(err){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+[$recv($globals.ErrorHandler)._handleError_(err)
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx2.sendIdx["handleError:"]=1
+//>>excludeEnd("ctx");
+][0];
+return [$recv(process)._exit_((1))
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx2.sendIdx["exit:"]=1
+//>>excludeEnd("ctx");
+][0];
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({err:err},$ctx1,1)});
+//>>excludeEnd("ctx");
+}))
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["on:do:"]=1
+//>>excludeEnd("ctx");
+][0];
+$recv($1)._on_do_("unhandledRejection",(function(err){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+$recv($globals.ErrorHandler)._handleError_(err);
+return $recv(process)._exit_((2));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({err:err},$ctx1,2)});
+//>>excludeEnd("ctx");
+}));
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"initialize",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.NodePlatform);
+
 $core.addMethod(
 $core.method({
 selector: "newXhr",

+ 10 - 0
lang/src/Platform-Node.st

@@ -12,6 +12,16 @@ globals
 	^ global
 ! !
 
+!NodePlatform methodsFor: 'initialization'!
+
+initialize
+	process
+		on: 'uncaughtException'
+		do: [ :err | ErrorHandler handleError: err. process exit: 1 ];
+		on: 'unhandledRejection'
+		do: [ :err | ErrorHandler handleError: err. process exit: 2 ]
+! !
+
 !NodePlatform methodsFor: 'public API'!
 
 fetch: aStringOrObject