packages/core/diagnostics
'info' is a real finding worth showing but never a validation failure -- exitCodeForViolations below only ever fails a run on 'error', so adding it here never changes what makes construct validate exit non-zero.
Core engine, v0.8. Source: packages/core/diagnostics.mjs.
Classes#
ConstructError#
Defined in: packages/core/diagnostics.mjs:18
An error that carries the violations that caused it and the process exit code the CLI should use. Thrown by commands that must stop (validation failures, usage errors); packages/core/cli.mjs turns it into an exit status.
Example#
throw new ConstructError("2 violations", { violations, exitCode: EXIT_CODES.VIOLATIONS });
Since#
0.8
Extends#
Error
Constructors#
Constructor
new ConstructError(
message,__namedParameters?):ConstructError
Defined in: packages/core/diagnostics.mjs:19
Parameters
message
any
__namedParameters?
exitCode?
number = EXIT_CODES.INTERNAL_ERROR
violations?
any[] = []
Returns
Overrides
Error.constructor
Properties#
exitCode
exitCode:
number
Defined in: packages/core/diagnostics.mjs:23
name
name:
string
Defined in: packages/core/diagnostics.mjs:21
Inherited from
Error.name
violations
violations:
any[]
Defined in: packages/core/diagnostics.mjs:22
Variables#
EXIT_CODES#
constEXIT_CODES:object
Defined in: packages/core/diagnostics.mjs:8
Type Declaration#
INTERNAL_ERROR
INTERNAL_ERROR:
number=3
OK
OK:
number=0
USAGE_ERROR
USAGE_ERROR:
number=2
VIOLATIONS
VIOLATIONS:
number=1
Functions#
assertValidViolation()#
assertValidViolation(
v):true
Defined in: packages/core/diagnostics.mjs:34
Check that a violation object has every required field and valid severity, module and expected values.
Parameters#
v
any
Violation to check.
Returns#
true
Always true when valid.
Throws#
Naming the missing or invalid field.
exitCodeForViolations()#
exitCodeForViolations(
violations):number
Defined in: packages/core/diagnostics.mjs:84
The process exit code for a set of violations: only error severity fails the run.
Parameters#
violations
any[]
Violation objects.
Returns#
number
EXIT_CODES.VIOLATIONS (1) if any violation has severity error, else EXIT_CODES.OK (0).
formatReport()#
formatReport(
violations,options?):string
Defined in: packages/core/diagnostics.mjs:71
Render violations for the terminal or as JSON.
Parameters#
violations
any[]
Violation objects from makeViolation.
options?
json returns {status, violations} as a string.
format?
"json" | "text" = 'text'
Returns#
string
The report text (a one-line pass message when there are no violations).
formatViolation()#
formatViolation(
v):string
Defined in: packages/core/diagnostics.mjs:55
Parameters#
v
any
Returns#
string
makeViolation()#
makeViolation(
input):object
Defined in: packages/core/diagnostics.mjs:49
Build and validate a diagnostic-contract violation object.
Parameters#
input
docsUrl?
string
expected?
string[] = []
file
string
line
number
message
string
module
string
rule
string
severity
string
suggestedFix?
string
why
string
Returns#
object
docsUrl
docsUrl:
string
expected
expected:
string[]
file
file:
string
line
line:
number
message
message:
string
module
module:
string
rule
rule:
string
severity
severity:
string
suggestedFix
suggestedFix:
string
why
why:
string