mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
DRY out error constructors, plus a couple of small fixes
- error messages won't end with '\nundefined' if meta.comment is missing - better prototypal inheritance
This commit is contained in:
parent
d5991a2d71
commit
461bc2c8ac
@ -9,24 +9,37 @@
|
||||
|
||||
|
||||
var dictionary = require('jsdoc/tag/dictionary');
|
||||
var format = require('util').format;
|
||||
|
||||
function buildMessage(tagName, meta, desc) {
|
||||
var result = format('The @%s tag %s. File: %s, line: %s', tagName, desc, meta.filename,
|
||||
meta.lineno);
|
||||
if (meta.comment) {
|
||||
result += '\n' + meta.comment;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function UnknownTagError(tagName, meta) {
|
||||
this.name = 'UnknownTagError';
|
||||
this.message = 'The @' + tagName + ' tag is not a known tag. File: ' + meta.filename + ', Line: ' + meta.lineno + '\n' + meta.comment;
|
||||
this.message = buildMessage(tagName, meta, 'is not a known tag');
|
||||
}
|
||||
UnknownTagError.prototype = Error.prototype;
|
||||
UnknownTagError.prototype = new Error();
|
||||
UnknownTagError.prototype.constructor = UnknownTagError;
|
||||
|
||||
function TagValueRequiredError(tagName, meta) {
|
||||
this.name = 'TagValueRequiredError';
|
||||
this.message = 'The @' + tagName + ' tag requires a value. File: ' + meta.filename + ', Line: ' + meta.lineno + '\n' + meta.comment;
|
||||
this.message = buildMessage(tagName, meta, 'requires a value');
|
||||
}
|
||||
TagValueRequiredError.prototype = Error.prototype;
|
||||
TagValueRequiredError.prototype = new Error();
|
||||
TagValueRequiredError.prototype.constructor = TagValueRequiredError;
|
||||
|
||||
function TagValueNotPermittedError(tagName, meta) {
|
||||
this.name = 'TagValueNotPermittedError';
|
||||
this.message = 'The @' + tagName + ' tag does not permit a value. File: ' + meta.filename + ', Line: ' + meta.lineno + '\n' + meta.comment;
|
||||
this.message = buildMessage(tagName, meta, 'does not permit a value');
|
||||
}
|
||||
TagValueNotPermittedError.prototype = Error.prototype;
|
||||
TagValueNotPermittedError.prototype = new Error();
|
||||
TagValueNotPermittedError.prototype.constructor = TagValueNotPermittedError;
|
||||
|
||||
/**
|
||||
Validate the given tag.
|
||||
|
||||
@ -21,7 +21,7 @@ exports.handle = function(e) {
|
||||
|
||||
// include the error type if it's an Error object
|
||||
if (e instanceof Error) {
|
||||
msg = e.constructor.name + ": " + msg;
|
||||
msg = e.name + ': ' + msg;
|
||||
}
|
||||
|
||||
console.log(msg);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user