-
Notifications
You must be signed in to change notification settings - Fork 0
Error management in command's action
Vincent Peybernes edited this page Jul 26, 2013
·
3 revisions
Command.IO provide a custom error management system, to protect the application execution from end user error.
Command.IO provide two custom error type: CommandError
and RuntimeCommandError
. This errors inherit of the JavaScript Error object with two additionnal properties: the command
name what throw the error and the severity level
of the error.
The error are provided by the command controler (this
in action function).
All errors throwed in command action are analysed by Command.IO.
- If a
RuntimeCommandError
are catch it throwed on runtime and stop the execution. - If is a
CommandError
and if his severity level is under the catching level, the error are only logged. Else it throwed on runtime.
Only CommandError are catch for now.
The catching level can be configured in the command descriptor with the èxceptionCatchLvl`property. View command descriptor
// Load module : require('command.io')
var commandio = require('..');
commandio.addCommand({
name: 'notice',
description: 'This command only log a notice',
action: function(){
// Throw error with notice level.
throw new this.CommandError('This is a notice.', this.errorLvl.notice);
}
});
commandio.addCommand({
name: 'error',
description: 'This command only log an error',
action: function(){
// Throw error with default error level.
throw new this.CommandError('This is an error.');
}
});
commandio.addCommand({
name: 'critical',
description: 'This command throw a critical error and stop program.',
action: function(){
// Throw error with critical error level.
throw new this.CommandError('This is an error.', this.errorLvl.critical);
}
});
commandio.addCommand({
name: 'throw-error',
description: 'This command throw an error and stop program',
exceptionCatchLvl: commandio.errorLvl.error,
action: function(){
// Throw error with default error level.
throw new this.CommandError('This is an error.');
}
});
commandio.addCommand({
name: 'runtime',
description: 'This throw a runtime error and stop program',
action: function(){
// Throw runtime error.
throw new this.RuntimeCommandError('This is a runtime error.');
}
});