@boringparts/verule 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.js ADDED
@@ -0,0 +1,41 @@
1
+ import { TssaeError, } from "tssae";
2
+ export const REPORT_SCHEMA_VERSION = "1";
3
+ /** Execution failure raised when analysis configuration, loading, queries, or rules fail. */
4
+ export class VeruleExecutionError extends Error {
5
+ code;
6
+ conflict;
7
+ constructor(code, message, options) {
8
+ super(message, options);
9
+ this.name = "VeruleExecutionError";
10
+ this.code = code;
11
+ if (options?.conflict !== undefined) {
12
+ this.conflict = options.conflict;
13
+ }
14
+ }
15
+ }
16
+ /** Maps upstream `TssaeError` or unknown exceptions into `VeruleExecutionError`. */
17
+ export function toVeruleError(error, fallbackCode = "ENGINE_ERROR") {
18
+ if (error instanceof VeruleExecutionError) {
19
+ return error;
20
+ }
21
+ if (error instanceof TssaeError) {
22
+ return new VeruleExecutionError(error.code, error.message, {
23
+ cause: error,
24
+ ...(error.conflict !== undefined ? { conflict: error.conflict } : {}),
25
+ });
26
+ }
27
+ if (error instanceof Error &&
28
+ error.name === "TssaeError" &&
29
+ "code" in error &&
30
+ typeof error.code === "string") {
31
+ const conflict = "conflict" in error && error.conflict !== undefined
32
+ ? error.conflict
33
+ : undefined;
34
+ return new VeruleExecutionError(error.code, error.message, {
35
+ cause: error,
36
+ ...(conflict !== undefined ? { conflict } : {}),
37
+ });
38
+ }
39
+ const message = error instanceof Error ? error.message : String(error);
40
+ return new VeruleExecutionError(fallbackCode, message, { cause: error });
41
+ }