Home / Function/ formatErrorStackTrace() — astro Function Reference

formatErrorStackTrace() — astro Function Reference

Architecture documentation for the formatErrorStackTrace() function in messages.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  bb067dbf_824d_9dc3_bda6_399e13135841["formatErrorStackTrace()"]
  a89de736_d85a_fc8a_68a9_5d9ea54128d5["messages.ts"]
  bb067dbf_824d_9dc3_bda6_399e13135841 -->|defined in| a89de736_d85a_fc8a_68a9_5d9ea54128d5
  c22b7b22_a441_ec90_5614_6cba0ae12199["formatErrorMessage()"]
  c22b7b22_a441_ec90_5614_6cba0ae12199 -->|calls| bb067dbf_824d_9dc3_bda6_399e13135841
  style bb067dbf_824d_9dc3_bda6_399e13135841 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/core/messages.ts lines 233–264

function formatErrorStackTrace(
	err: Error | ErrorWithMetadata,
	showFullStacktrace: boolean,
): string {
	const stackLines = (err.stack || '').split('\n').filter((line) => STACK_LINE_REGEXP.test(line));
	// If full details are required, just return the entire stack trace.
	if (showFullStacktrace) {
		return stackLines.join('\n');
	}
	// Grab every string from the user's codebase, exit when you hit node_modules or astro/dist
	const irrelevantStackIndex = stackLines.findIndex((line) => IRRELEVANT_STACK_REGEXP.test(line));
	if (irrelevantStackIndex <= 0) {
		const errorId = (err as ErrorWithMetadata).id;
		const errorLoc = (err as ErrorWithMetadata).loc;
		if (errorId || errorLoc?.file) {
			const prettyLocation = `    at ${errorId ?? errorLoc?.file}${
				errorLoc?.line && errorLoc.column ? `:${errorLoc.line}:${errorLoc.column}` : ''
			}`;
			return (
				prettyLocation + '\n    [...] See full stack trace in the browser, or rerun with --verbose.'
			);
		} else {
			return stackLines.join('\n');
		}
	}
	// If the error occurred inside of a dependency, grab the entire stack.
	// Otherwise, only grab the part of the stack that is relevant to the user's codebase.
	return (
		stackLines.splice(0, irrelevantStackIndex).join('\n') +
		'\n    [...] See full stack trace in the browser, or rerun with --verbose.'
	);
}

Domain

Subdomains

Frequently Asked Questions

What does formatErrorStackTrace() do?
formatErrorStackTrace() is a function in the astro codebase, defined in packages/astro/src/core/messages.ts.
Where is formatErrorStackTrace() defined?
formatErrorStackTrace() is defined in packages/astro/src/core/messages.ts at line 233.
What calls formatErrorStackTrace()?
formatErrorStackTrace() is called by 1 function(s): formatErrorMessage.

Analyze Your Own Codebase

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

Try Supermodel Free