Home / Function/ enhanceCSSError() — astro Function Reference

enhanceCSSError() — astro Function Reference

Architecture documentation for the enhanceCSSError() function in style.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  9a23543d_a158_1ce7_2b6e_5866fa1c8f6e["enhanceCSSError()"]
  b49b1fb8_9e6f_4c97_cf66_98d4fd2b7754["style.ts"]
  9a23543d_a158_1ce7_2b6e_5866fa1c8f6e -->|defined in| b49b1fb8_9e6f_4c97_cf66_98d4fd2b7754
  0160d787_c349_53b5_38f7_e3c1aa80c392["createStylePreprocessor()"]
  0160d787_c349_53b5_38f7_e3c1aa80c392 -->|calls| 9a23543d_a158_1ce7_2b6e_5866fa1c8f6e
  style 9a23543d_a158_1ce7_2b6e_5866fa1c8f6e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/core/compile/style.ts lines 132–186

function enhanceCSSError(err: any, filename: string, cssContent: string) {
	const fileContent = fs.readFileSync(filename).toString();
	const styleTagBeginning = fileContent.indexOf(cssContent);

	// PostCSS Syntax Error
	if (err.name === 'CssSyntaxError') {
		const errorLine = positionAt(styleTagBeginning, fileContent).line + (err.line ?? 0);

		// Vite will handle creating the frame for us with proper line numbers, no need to create one

		return new CSSError({
			...AstroErrorData.CSSSyntaxError,
			message: err.reason,
			location: {
				file: filename,
				line: errorLine,
				column: err.column,
			},
			stack: err.stack,
		});
	}

	// Some CSS processor will return a line and a column, so let's try to show a pretty error
	if (err.line && err.column) {
		const errorLine = positionAt(styleTagBeginning, fileContent).line + (err.line ?? 0);

		return new CSSError({
			...AstroErrorData.UnknownCSSError,
			message: err.message,
			location: {
				file: filename,
				line: errorLine,
				column: err.column,
			},
			frame: err.frame,
			stack: err.stack,
		});
	}

	// For other errors we'll just point to the beginning of the style tag
	const errorPosition = positionAt(styleTagBeginning, fileContent);
	errorPosition.line += 1;

	return new CSSError({
		name: 'CSSError',
		message: err.message,
		location: {
			file: filename,
			line: errorPosition.line,
			column: 0,
		},
		frame: err.frame,
		stack: err.stack,
	});
}

Domain

Subdomains

Frequently Asked Questions

What does enhanceCSSError() do?
enhanceCSSError() is a function in the astro codebase, defined in packages/astro/src/core/compile/style.ts.
Where is enhanceCSSError() defined?
enhanceCSSError() is defined in packages/astro/src/core/compile/style.ts at line 132.
What calls enhanceCSSError()?
enhanceCSSError() is called by 1 function(s): createStylePreprocessor.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free