xref: /third_party/node/test/parallel/test-unhandled-exception-rethrow-error.js (revision 1cb0ef41)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_cirequire('../common');
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciif (process.argv[2] === 'child') {
51cb0ef41Sopenharmony_ci  process.on('uncaughtException', (err) => {
61cb0ef41Sopenharmony_ci    err.rethrow = true;
71cb0ef41Sopenharmony_ci    throw err;
81cb0ef41Sopenharmony_ci  });
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci  function throwException() {
111cb0ef41Sopenharmony_ci    throw new Error('boom');
121cb0ef41Sopenharmony_ci  }
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci  throwException();
151cb0ef41Sopenharmony_ci} else {
161cb0ef41Sopenharmony_ci  const assert = require('assert');
171cb0ef41Sopenharmony_ci  const { spawnSync } = require('child_process');
181cb0ef41Sopenharmony_ci  const result = spawnSync(process.execPath, [__filename, 'child']);
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci  assert.strictEqual(result.status, 7);
211cb0ef41Sopenharmony_ci  assert.strictEqual(result.signal, null);
221cb0ef41Sopenharmony_ci  assert.strictEqual(result.stdout.toString().trim(), '');
231cb0ef41Sopenharmony_ci  // Verify that the error was thrown and that the stack was preserved.
241cb0ef41Sopenharmony_ci  const stderr = result.stderr.toString();
251cb0ef41Sopenharmony_ci  assert.match(stderr, /Error: boom/);
261cb0ef41Sopenharmony_ci  assert.match(stderr, /at throwException/);
271cb0ef41Sopenharmony_ci  assert.match(stderr, /rethrow: true/);
281cb0ef41Sopenharmony_ci}
29

Indexes created Thu Nov 07 10:32:03 CST 2024