0.10.1 • Published 3 years ago

@dazn/chaos-squirrel-attack-throw-error v0.10.1

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

@dazn/chaos-squirrel-attack-throw-error

Causes an error to be thrown - either directly or via setImmediate causing uncaught exception.

Attack options

ParameterTypeDefaultDescription
errorClassErrConstructorErrorInstance of that class will be thrown. The class should extend Error.
errorMessagestringchaos-squirrel: attack-throw-errorError message
uncaughtExceptionbooleanfalseFlag that decides if uncaught exception is thrown

Examples

Immediately thrown error

import ThrowErrorAttack from '@dazn/chaos-squirrel-attack-throw-error';;

class CustomError extends Error {
  constructor(message?: string) {
    super(message);
  }
}
const errorMessage = 'Chaos!';
const attack = new ThrowErrorAttack({
    errorClass: CustomError,
    errorMessage
});

try {
    attack.start();
} catch (err) {
    err instanceof CustomError // true
    console.log(err.message) // Chaos!
}

Uncaught exception

import ThrowErrorAttack from '@dazn/chaos-squirrel-attack-throw-error';

const attack = new ThrowErrorAttack({ uncaughtException: true });

process.on('uncaughtException', (err) => {
    err instanceof Error // true
    console.log(err.message) // chaos-squirrel: attack-throw-error
})

attack.start();
console.log('Still alive');
// Uncaught exception is thrown via setImmediate so "check" phase

Stopping uncaught exception

import ThrowErrorAttack from '@dazn/chaos-squirrel-attack-throw-error';

const attack = new ThrowErrorAttack({ uncaughtException: true });

attack.start();
attack.stop();
// nothing bad is gonna happen

Uncaught exception

To cause an uncaught exception an error is being thrown from setImmediate callback. See docs.

0.10.1

3 years ago

0.10.0

3 years ago

0.9.9

3 years ago

0.9.8

3 years ago

0.9.7

3 years ago

0.9.5

3 years ago

0.9.4

4 years ago