Error Handling

How DocLayer validates and reports errors in authoring, build, and production

DocLayer fails loudly while you write and build, then stays quiet in production. Authors see mistakes immediately, prerender refuses to ship broken content, and visitors are never blocked by a validation warning.

Error Handling Overview

It's important to understand that each of these stages is mainly handled by different tools - Vue, Vite, Rollup, Nitro - each responsible for a specific part of the pipeline. While this might seem like a drawback, it can be treated as a strength because it allows for very granular control over the entire process. At the same time, it's important to ensure the approach is as universal and consistent as possible, sharing the same logic across.

Below we present a detailed breakdown of how the errors are handled at each stage of the pipeline, starting from authoring - the most common use case for DocLayer - through development, build, and production.

Authoring

Every Markdown file you create in your editor is validated by the internal Markdownlint ruleset. Additionally, we have extended this with custom rules that check specifically for the usage and structure of DocLayer’s custom content components in your content. More about Markdownlint, its rules and setup, you can read here.

Markdown metadata is validated by Zod, following Nuxt Content conventions. This ensures that the frontmatter-oriented data is checked for correct format, and validation succeeds prior to document displaying. More about defining content metadata within collections, you can read here.

Development

Our internal content components (like DlCode, DlCallout, DlLink, etc.) and pages are guarded and validated using the useContentGuard composable. It provides a universal and polymorphic approach to error handling and its presentation (with custom error.vue page). It's highly recommended to use it in your own components and pages to ensure the consistency and reliability of your content.

On the server the guard throws so SSR can render error.vue; on the client it calls showError() after hydration. Throwing during setup would abort navigation and cancel hydration.

As noted above, DocLayer automatically provides a custom error.vue page to display user-friendly error messages. This page is automatically added each time you run the nuxt prepare command. If you prefer to use your own error page, you can prevent this automation by setting the rootPrep module option to false.

During development, you may encounter various errors and warnings. To provide the best possible experience and maintain content reliability, DocLayer automatically mutes warnings and notifications that are known to be harmless or simply add unnecessary noise. This is achieved through a custom and universal (client and server-side) plugin that sets up warn handlers using a predefined set of patterns and filters. You can extend or override these patterns to fit your needs by using the utilWarnPatternCheck utility - of course with your own handler instead. This runtime filter is always on for the known patterns; it is not toggled by debug.

All logs - warnings, errors, etc. - are managed using the utilLogger utility. This utility is built on top of Consola and delivers a consistent, universal logging strategy. It is strongly recommended for use in your own components. Pairing utilLogger with utilLogMessage further improves the formatting and clarity of your log messages, providing users with complete context about any issues that occur.

Building & Bundling

It's important to distinguish the building and bundling stages from the final prerender. Because DocLayer builds statically by default, these steps happen sequentially and are managed by different tools depending on the environment: Vite and Rollup take care of bundling and building, while Nitro is responsible for further server asset building and for prerendering.

For both Vite (which manages the initial startup and hands off to Rollup) and Rollup (handling the main build), we use custom plugins to manage warnings and errors. These plugins suppress warnings considered minor or irrelevant to the build process. Each plugin has filters and patterns specific to its stage, and both use the utilWarnPatternCheck utility to further fine-tune which warnings get filtered.

On this stage, enabling full logging also works with the debug module option - the same flag as everywhere else, not a separate switch per tool; more granular logging coming soon.

Prerender

Now, mentioned before - rendering, done by Nitro. Our initial configuration sets the failOnError option to true, which means Nitro will terminate the build if a prerendered route throws. console.warn alone does not fail the build. Since our content is already protected by the useContentGuard composable - which also plays a role at this stage - any error that slips through will cause the build to fail. This makes it crucial to use the guard utility correctly and consistently. Its foundation is designed to provide clear, detailed logging during development and to ensure that errors are caught and reported if they reach the build stage, before accidentally deploying a broken application.

It's worth noting that some of this stage warnings were also filtered by the utilWarnPatternCheck. The Nitro errorHandler is only a debug tap (debug / NITRO_EVENTS) - it does not replace error.vue.

Production

In production, logs are disabled by default because the security preset suppresses them. If you need to debug in production, you can enable logging with DL_SECURITY_PROD_LOG=true. Be mindful that exposing internal logs may lead to security vulnerabilities and reveal application issues.

Lastly, the useContentGuard composable can also play an important role at this stage: it logs and does not throw, so a bad content block will not replace the whole page with error.vue. If any content block fails to render, you can use a simple flag (set by the dedicated fallback function) in your component or page template to skip rendering the broken "island". More about this feature, you can read here.

Step 0 of 0

Tooling Guideline

Here's a simplified table of how the errors are handled within the lifecycle.

StageDescription

Authoring
(writing content)

Validate Markdown to detect errors in custom components, and collection frontmatter before the app boots.

Development
(e.g. building components)

Guard content, show fatal errors, mute known Vue noise, log with a shared format.

Building & Bundling

Suppress known bundler warnings.

Prerender
(generating static routes)

Thrown route errors fail the deploy. The Nitro handler is a debug tap only.

Production

Logs off by default; any guard does not throw. Broken blocks can be hidden additionally.