UNPKG

@lwc/errors

Version:

LWC Error Utilities

59 lines 3.24 kB
import { CompilerError } from './utils'; import type { LWCErrorInfo } from '../shared/types'; import type { CompilerDiagnosticOrigin, CompilerDiagnostic } from './utils'; export { CompilerDiagnosticOrigin, CompilerDiagnostic, CompilerError } from './utils'; export * from './error-info'; export interface ErrorConfig { messageArgs?: any[]; origin?: CompilerDiagnosticOrigin; } /** * Generates a friendly error message for the given error type, using the provided template values. * @param errorInfo The object holding the error metadata. * @param args Values used to fill the error message template. * @returns The generated error message. */ export declare function generateErrorMessage(errorInfo: LWCErrorInfo, args?: any[]): string; /** * Generates a compiler diagnostic. This function is used to look up the specified errorInfo * and generate a friendly and consistent diagnostic object. Diagnostic contains * info about the error's code and its origin (filename, line, column) when applicable. * @param errorInfo The object holding the error metadata. * @param config A config object providing any message arguments and origin info needed to create the error. * @returns The generated compiler diagnostic object. */ export declare function generateCompilerDiagnostic(errorInfo: LWCErrorInfo, config?: ErrorConfig): CompilerDiagnostic; /** * Generates a compiler error. This function is used to look up the specified errorInfo * and generate a friendly and consistent error object. Error object contains info about * the error's code and its origin (filename, line, column) when applicable. * @param errorInfo The object holding the error metadata. * @param config A config object providing any message arguments and origin info needed to create the error. * @returns The generated compiler error. */ export declare function generateCompilerError(errorInfo: LWCErrorInfo, config?: ErrorConfig): CompilerError; /** * Validates that the provided condition is truthy. * @param condition Condition to check. * @param errorInfo The object holding the error metadata. * @param args Values used to fill the error message template. * @throws Throws a compiler error if the provided condition is falsy. */ export declare function invariant(condition: boolean, errorInfo: LWCErrorInfo, args?: any[]): void; /** * Normalizes a received error into a CompilerError. Adds any provided additional origin info. * @param errorInfo The object holding the error metadata. * @param error The original error. * @param origin The origin associated with the error. * @returns The normalized compiler error. */ export declare function normalizeToCompilerError(errorInfo: LWCErrorInfo, error: any, origin?: CompilerDiagnosticOrigin): CompilerError; /** * Normalizes a received error into a CompilerDiagnostic. Adds any provided additional origin info. * @param errorInfo The object holding the error metadata. * @param error The original error. * @param origin The origin of the error. * @returns The normalized compiler diagnostic object. */ export declare function normalizeToDiagnostic(errorInfo: LWCErrorInfo, error: any, origin?: CompilerDiagnosticOrigin): CompilerDiagnostic; //# sourceMappingURL=errors.d.ts.map