In this article, we review a commonly used utility named, throwError in Infero.js source code.
export function renderInternal( input: VNode | InfernoNode, parentDOM: ParentDOM, callback: (() => void) | null, context: ContextObject,): void { // Development warning if (process.env.NODE_ENV !== 'production') { if (documentBody === parentDOM) { throwError( 'you cannot render() to the "document.body". Use an empty element as a container instead.', ); } if (isInvalid(parentDOM)) { throwError( `render target ( DOM ) is mandatory, received ${ parentDOM === null ? 'null' : typeof parentDOM }`, ); } }
export function throwError(message?: string): void { if (!message) { message = ERROR_MSG; } throw new Error(`Inferno Error: ${message}`);}
The message argument here is just a string, but you see that variable ERROR_MSG that is used a fallback in case there is no message, i.e., message is empty string or null or undefined? this ERROR_MSG is defined at the top of the same file.
export const ERROR_MSG = 'a runtime error occured! Use Inferno in development environment to find the error.';
Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.
Configure features such as Changesets in your Next.js project usingThink Throo CLI.