-
Notifications
You must be signed in to change notification settings - Fork 5
XMLMessages
do- edited this page Apr 21, 2026
·
10 revisions
XMLMessages is a static utility class for consistent error reporting across xml-toolkit.
It centralizes:
- error code definitions (human-readable templates),
- message formatting with argument substitution,
- error object creation with debug metadata.
The standard util.format is used as a template system.
XMLMessages.VOCABULARY.set ('XVC-00005', `Il manque l'attribut obligatiore: "%s"`)if (!node.attributes.has('id')) {
XMLMessages.raise (['XVC-00005', 'id'])
}process.on ('uncaughtException', err => {
if (err.args?.[0]?.startsWith('XVS-')) {
// Handle simple type validation errors specially
logger.warn('Data validation failed:', err.message)
} else {
throw err
}
})Formats an error message by substituting arguments into the template.
| Param | Type | Description |
|---|---|---|
args |
Array |
[code, ...substitutions] — error code followed by values for %s, %i, %j etc. |
Returns: string — formatted message with code prefix.
Example:
XMLMessages.format(['XVS-00004', 'abc', 3, 2])
// → 'XVS-00004 The value \'abc\' has the length 3, which exceeds the allowed maximum of 2'Creates and throws an Error with formatted message and debug metadata.
| Param | Type | Description |
|---|---|---|
args |
Array |
Same as for format()
|
Throws: Error with properties:
| Property | Type | Description |
|---|---|---|
message |
string |
Formatted error text (code + description) |
args |
Array |
Original arguments array (for debugging/logging) |
Example:
try {
XMLMessages.raise(['XVC-00005', 'id'])
} catch (e) {
console.log(e.message) // 'XVC-00005 Missing required attribute: "id"'
console.log(e.args) // ['XVC-00005', 'id']
}All messages are stored in XMLMessages.VOCABULARY — a Map<code, template>.
| Prefix | Scope | Example codes |
|---|---|---|
XML- |
Core XML parsing |
XML-00001, XML-00002, XML-00003
|
XSD- |
XML Schema definitions |
XSD-00001, XSD-00002
|
XVC- |
Validation: structure/constraints |
XVC-00001 … XVC-00005
|
XVS- |
Validation: simple type values |
XVS-00001 … XVS-00041
|
| Code | Template | When raised |
|---|---|---|
XML-00001 |
maxLength=%i exceeded |
XMLLexer encountered a lexeme longer than maxLength option |
XML-00002 |
Unbalanced end element |
</tag> without matching <tag>
|
XML-00003 |
Unmatched end element, %s expected |
</wrong> when </expected> was anticipated |
| Code | Template | When raised |
|---|---|---|
XSD-00001 |
Unknown namespace: %s |
Referenced namespace not found in loaded schemas |
XSD-00002 |
The element %s is not found in %s |
Element used but not declared in schema |
| Code | Template | When raised |
|---|---|---|
XVC-00001 |
No nested elements allowed inside %s |
Complex type with simpleContent received child elements |
XVC-00002 |
%s is unexpected here; should be %s |
Element order violates xs:sequence/xs:choice
|
XVC-00003 |
Unknown attribute: %s |
Attribute not declared in schema |
XVC-00004 |
The attribute "%s" must have the value "%s", not "%s" |
Fixed-value attribute mismatch |
XVC-00005 |
Missing required attribute: "%s" |
Required attribute absent |
| Code | Template | When raised |
|---|---|---|
XVS-00001 |
The value "%s" doesn't match the pattern %s |
xs:pattern facet mismatch |
XVS-00003 |
The value '%s' is not in list: %s |
xs:enumeration facet mismatch |
XVS-00004–006
|
Length constraint violations |
xs:minLength/maxLength/length
|
XVS-00007–0010
|
Range constraint violations |
xs:minInclusive/maxExclusive etc. |
XVS-00011–00012
|
Boolean parsing errors | Invalid true/false/1/0
|
XVS-00013–00019
|
Decimal parsing errors | Invalid format, digit count, precision |
XVS-00020–00021
|
Float parsing errors | Invalid floating-point syntax |
XVS-00022–00041
|
Date/time parsing errors | Invalid date, time, timezone, separators |