Home / Function/ getSafeErrorMessage() — astro Function Reference

getSafeErrorMessage() — astro Function Reference

Architecture documentation for the getSafeErrorMessage() function in error.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  b67009d2_5e75_6ab7_6873_01b18a5a3c32["getSafeErrorMessage()"]
  2bf4188d_3294_32f2_7216_e6a2a60569ef["error.ts"]
  b67009d2_5e75_6ab7_6873_01b18a5a3c32 -->|defined in| 2bf4188d_3294_32f2_7216_e6a2a60569ef
  631b6819_275c_cd3e_e724_2bb6eb5bb160["eventError()"]
  631b6819_275c_cd3e_e724_2bb6eb5bb160 -->|calls| b67009d2_5e75_6ab7_6873_01b18a5a3c32
  style b67009d2_5e75_6ab7_6873_01b18a5a3c32 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/events/error.ts lines 86–112

function getSafeErrorMessage(message: string | Function): string {
	if (typeof message === 'string') {
		return message;
	} else {
		return String.raw({
			raw: extractStringFromFunction(message.toString()),
		});
	}

	function extractStringFromFunction(func: string) {
		const arrowIndex = func.indexOf('=>') + '=>'.length;

		return func
			.slice(arrowIndex)
			.trim()
			.slice(1, -1)
			.replace(
				/\$\{([^}]+)\}/g,
				(_str, match1) =>
					`${match1
						.split(/\.?(?=[A-Z])/)
						.join('_')
						.toUpperCase()}`,
			)
			.replace(/\\`/g, '`');
	}
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does getSafeErrorMessage() do?
getSafeErrorMessage() is a function in the astro codebase, defined in packages/astro/src/events/error.ts.
Where is getSafeErrorMessage() defined?
getSafeErrorMessage() is defined in packages/astro/src/events/error.ts at line 86.
What calls getSafeErrorMessage()?
getSafeErrorMessage() is called by 1 function(s): eventError.

Analyze Your Own Codebase

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

Try Supermodel Free