Diagnostics API

AddonovaError, Diagnostic, and conversion helpers.

#
import {
  AddonovaError,
  createDiagnostic,
  isAddonovaError,
  toDiagnostic,
} from 'addonova';

Diagnostic

#
type DiagnosticSeverity = 'error' | 'warning' | 'info';

interface DiagnosticLocation {
  file: string;
  line?: number;
  column?: number;
}

interface Diagnostic {
  code: string;
  severity: DiagnosticSeverity;
  message: string;
  location?: DiagnosticLocation;
  suggestion?: string;
  cause?: unknown;
}

AddonovaError

#
class AddonovaError extends Error {
  readonly diagnostic: Diagnostic;
  get code(): string;
  get severity(): DiagnosticSeverity;
  get location(): DiagnosticLocation | undefined;
  get suggestion(): string | undefined;
}
try {
  await build();
} catch (error) {
  if (isAddonovaError(error)) {
    console.error(error.code, error.message);
  }
}

createDiagnostic

#
function createDiagnostic(diagnostic: Diagnostic): Diagnostic;

Identity helper for typed diagnostics.

isAddonovaError

#
function isAddonovaError(value: unknown): value is AddonovaError;

toDiagnostic

#
function toDiagnostic(error: unknown, code = 'ADDONOVA_UNKNOWN'): Diagnostic;

Returns the wrapped diagnostic for AddonovaError, or wraps any Error or value into an error diagnostic with an optional code.

Severity behavior

#
  • error fails commands and builds.
  • warning is printed but does not change the exit code.
  • info is informational output.

Codes are listed in Error codes.

Edit this page on GitHub