enhanceCompileError() — astro Function Reference
Architecture documentation for the enhanceCompileError() function in compile.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 66e8c65c_f904_e726_dc60_4a26d3071e0d["enhanceCompileError()"] a1b2a752_beb5_d4f4_ce1d_6f9443e365d3["compile.ts"] 66e8c65c_f904_e726_dc60_4a26d3071e0d -->|defined in| a1b2a752_beb5_d4f4_ce1d_6f9443e365d3 59d5ea7d_ccd5_fdc2_7a73_cc8ac4e8604a["compileAstro()"] 59d5ea7d_ccd5_fdc2_7a73_cc8ac4e8604a -->|calls| 66e8c65c_f904_e726_dc60_4a26d3071e0d style 66e8c65c_f904_e726_dc60_4a26d3071e0d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/vite-plugin-astro/compile.ts lines 95–137
async function enhanceCompileError({
err,
id,
source,
}: EnhanceCompilerErrorOptions): Promise<void> {
const lineText = (err as any).loc?.lineText;
// Verify frontmatter: a common reason that this plugin fails is that
// the user provided invalid JS/TS in the component frontmatter.
// If the frontmatter is invalid, the `err` object may be a compiler
// panic or some other vague/confusing compiled error message.
//
// Before throwing, it is better to verify the frontmatter here, and
// let esbuild throw a more specific exception if the code is invalid.
// If frontmatter is valid or cannot be parsed, then continue.
const scannedFrontmatter = frontmatterRE.exec(source);
if (scannedFrontmatter) {
// Top-level return is not supported, so replace `return` with throw
const frontmatter = scannedFrontmatter[1].replace(/\breturn\b/g, 'throw');
// If frontmatter does not actually include the offending line, skip
if (lineText && !frontmatter.includes(lineText)) throw err;
try {
await transformWithEsbuild(frontmatter, id, {
loader: 'ts',
target: 'esnext',
sourcemap: false,
});
} catch (frontmatterErr: any) {
// Improve the error by replacing the phrase "unexpected end of file"
// with "unexpected end of frontmatter" in the esbuild error message.
if (frontmatterErr?.message) {
frontmatterErr.message = frontmatterErr.message.replace(
'end of file',
'end of frontmatter',
);
}
throw frontmatterErr;
}
}
throw err;
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does enhanceCompileError() do?
enhanceCompileError() is a function in the astro codebase, defined in packages/astro/src/vite-plugin-astro/compile.ts.
Where is enhanceCompileError() defined?
enhanceCompileError() is defined in packages/astro/src/vite-plugin-astro/compile.ts at line 95.
What calls enhanceCompileError()?
enhanceCompileError() is called by 1 function(s): compileAstro.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free