Error handling recommendations
These recommendations are temporary. Existing code may not yet follow them everywhere.
CLI errors use
CLILevelError. These include errors reading or parsing the platform declaration file. Do not assign adiagnosticCodeto them.Model problems are reported with
logger.errororlogger.warn. Choose the level according to the severity. A log entry may include adiagnosticCodein itsopt, but the code is not mandatory for logs. When assigning a code, include useful context where possible, such as a component path or identifier, or the name of the file involved.jslogger.error('Invalid expression', {diagnosticCode: 'INVALID_EXPRESSION'});When the logger is unavailable or the current operation must be interrupted, use
HetaLevelError. AdiagnosticCodeis required. The second argument is stored inerror.optalong with any context. A handler may catch the exception and continue execution.jsthrow new HetaLevelError('Invalid expression', { diagnosticCode: 'INVALID_EXPRESSION', expression: 'x +' });Catch
HetaLevelErrorinside the application where possible and report it throughlogger.errororlogger.warn, passing on its message andopt. The handler chooses the log level. If the exception reaches the CLI, it is reported as an error and execution stops.The boundary between CLI and model errors is after the platform declaration has been read and parsed. Reading or parsing the declaration belongs to the CLI. Validating the loaded declaration and processing modules belong to
Builder; an invalid declaration structure is reported as aHetaLevelErroror a log entry.Internal application errors use an appropriate standard or other exception type, excluding
HetaLevelErrorandCLILevelError. Do not assign a model diagnostic code based only on an exception's type. As a temporary exception,MODULE_PROCESSING_ERRORcan represent either a module problem or an internal application error.
Diagnostic codes also cover platform and export configuration problems, export processes, unavailable files, and unsupported or invalid formats. The codes and their descriptions are defined in src/diagnostic-codes.json.