Provide exception console log on browser process 18/211918/4
authorYoungsoo Choi <kenshin.choi@samsung.com>
Mon, 12 Aug 2019 04:20:23 +0000 (21:20 -0700)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Mon, 12 Aug 2019 05:20:07 +0000 (22:20 -0700)
This provides nodejs exception console log on browser process
and refactors it to be used as a module exception_handling with pid.

Change-Id: I7859310070f973bff6ea9814e8b86605847224f5
Signed-off-by: Youngsoo Choi <kenshin.choi@samsung.com>
wrt_app/browser/wrt.js
wrt_app/common/exception_handling.js [new file with mode: 0644]
wrt_app/renderer/init.js
wrt_app/src/main.js

index b4fb83f..ea4a675 100755 (executable)
  *    See the License for the specific language governing permissions and
  *    limitations under the License.
  */
-
+require('../common/exception_handling');
 const {wrt} = process.binding('wrt');
-const {EventEmitter} = require('events')
-const util = require('util')
+const {EventEmitter} = require('events');
+const util = require('util');
 
-Object.setPrototypeOf(Object.getPrototypeOf(wrt), EventEmitter.prototype)
+Object.setPrototypeOf(Object.getPrototypeOf(wrt), EventEmitter.prototype);
 
-module.exports = wrt
+module.exports = wrt;
 
 console.log = console.error = console.warn = function(...args) {
   wrt.log(util.format(...args));
 };
 process.stdout.write = process.stderr.write = function (chunk, encoding, callback) {
   if (Buffer.isBuffer(chunk)) {
-    chunk = chunk.toString(encoding)
+    chunk = chunk.toString(encoding);
   }
-  wrt.log(chunk)
+  wrt.log(chunk);
   if (callback) {
-    callback()
+    callback();
   }
-  return true
+  return true;
 }
diff --git a/wrt_app/common/exception_handling.js b/wrt_app/common/exception_handling.js
new file mode 100644 (file)
index 0000000..028846d
--- /dev/null
@@ -0,0 +1,6 @@
+process.on('uncaughtException', function (error) {
+  // Do nothing if the user has a custom uncaught exception handler.
+  var ref, stack
+  stack = (ref = error.stack) != null ? ref : error.name + ': ' + error.message
+  console.error('A JavaScript error occurred in pid ' + process.pid + '\n' + stack)
+});
index 177283d..57f2e92 100755 (executable)
  *    limitations under the License.
  */
 
+require('../common/exception_handling');
 const wrtRenderer = require('./wrt_renderer');
 require(wrtRenderer.getElectronPath() + '/renderer/init')
-
-process.on('uncaughtException', function (error) {
-  // Do nothing if the user has a custom uncaught exception handler.
-  var ref, stack
-  stack = (ref = error.stack) != null ? ref : error.name + ': ' + error.message
-  console.error('A JavaScript error occurred in the renderer process\n' + stack)
-})
index aa07326..ae0de87 100755 (executable)
 
 'use strict';
 
-process.on('uncaughtException', function (error) {
-  // Do nothing if the user has a custom uncaught exception handler.
-  var ref, stack
-  stack = (ref = error.stack) != null ? ref : error.name + ': ' + error.message
-  console.error('A JavaScript error occurred in the main process\n' + stack)
-})
+require('../common/exception_handling');
 
 new (require('./runtime'))({
   devMode: false,