Incorrect type of returned validation error in JavaScript api (mjml2html), does not correspond to the stated documentation
Error in documentation
In this section of the documentation it is written that the type of error being raised is MJMLValidationError, but in fact it is ValidationError and it does not have getErrors and getMessages methods
To Reproduce
try {
mjmlResult = mjml2html(incorrectMjml, {validationLevel: 'strict'});
} catch (e) {
console.log(e)
}
Expected behavior
As written in this section docs:
strict will raise a MJMLValidationError exception. This object has 2 methods: getErrors returns an array of objects with line, message, tagName as well as a formattedMessage which contains the line, message and tagName concatenated in a sentence. getMessages returns an array of formattedMessage
Actual
ValidationError: ValidationError: {
...stacktrace...,
errors: [
{
line: 3,
message: "Element mj-attributess doesn't exist or is not registered",
tagName: 'mj-attributess',
formattedMessage: "Line 3 of /Users/path (mj-attributess) — Element mj-attributess doesn't exist or is not registered"
}
]
}
the object has no getErrors and getMessages methods, only the errors property
Additional
node_modules/mjml-core/lib/index.js:271
switch (validationLevel) {
case 'skip':
break;
case 'strict':
errors = (0, _mjmlValidator.default)(mjml, validatorOptions);
if (errors.length > 0) {
throw new ValidationError(`ValidationError: \n ${errors.map(e => e.formattedMessage).join('\n')}`, errors);
}
break;
case 'soft':
default:
errors = (0, _mjmlValidator.default)(mjml, validatorOptions);
break;
}
MJML environment:
- OS: MacOS
- MJML Version: 4.12.0
- MJML tool used: mjml2html JavaScript API
Most likely something not updated since MJML3 🤔
On 29 Jul 2022, at 14:09, Edward Konovalov @.***> wrote:
Error in documentation
In this section of the documentation it is written that the type of error being raised is MJMLValidationError, but in fact it is ValidationError and it does not have getErrors and getMessages methods
To Reproduce
try { mjmlResult = mjml2html(incorrectMjml, {validationLevel: 'strict'}); } catch (e) { console.log(e) } Expected behavior
As written in this section docs:
strict will raise a MJMLValidationError exception. This object has 2 methods: getErrors returns an array of objects with line, message, tagName as well as a formattedMessage which contains the line, message and tagName concatenated in a sentence. getMessages returns an array of formattedMessage
Actual
ValidationError: ValidationError: { ...stacktrace..., errors: [ { line: 3, message: "Element mj-attributess doesn't exist or is not registered", tagName: 'mj-attributess', formattedMessage: "Line 3 of /Users/path (mj-attributess) — Element mj-attributess doesn't exist or is not registered" } ] } the object has no getErrors and getMessages methods, only the errors property
Additional
node_modules/mjml-core/lib/index.js:271
switch (validationLevel) { case 'skip': break;
case 'strict': errors = (0, _mjmlValidator.default)(mjml, validatorOptions); if (errors.length > 0) { throw new ValidationError(`ValidationError: \n ${errors.map(e => e.formattedMessage).join('\n')}`, errors); } break; case 'soft': default: errors = (0, _mjmlValidator.default)(mjml, validatorOptions); break;} MJML environment:
OS: MacOS MJML Version: 4.12.0 MJML tool used: mjml2html JavaScript API — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.