errorHandling
Configure how the formatter handles parsing errors.
By default, the formatter returns the original content unchanged when a parsing error occurs. Set throwOnError: true to throw an error instead (useful for CI pipelines).
Options
| Property | Type | Default | Description |
|---|---|---|---|
throwOnError | boolean | false | If true, throw on errors. If false, return original content. |
Config
{
"errorHandling": {
"throwOnError": false
}
}
Examples
Graceful handling (default)
With throwOnError: false, malformed content is returned as-is:
Input:
# Heading
<InfoBox>
Content without closing tag
Output: the original content is returned unchanged, no error thrown.
Strict mode for CI
With throwOnError: true, the formatter throws an error on malformed content, which is useful for catching issues in CI pipelines:
import { format } from '@takazudo/mdx-formatter';
try {
const result = await format(content, {
settings: {
errorHandling: { throwOnError: true },
},
});
} catch (error) {
console.error('Formatting failed:', error.message);
process.exit(1);
}