/
errors.ts
107 lines (93 loc) · 2.39 KB
/
errors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
function escapedPanelIdentifier(id: number | string) {
return `[${String(id).replace(']', '\\]')}]`;
}
export class NotAnArrayOfObjectsError extends Error {
targetPanelId: number | string;
constructor(id: number | string) {
super();
this.name = 'NotAnArrayOfObjectsError';
this.targetPanelId = id;
this.message = `This panel requires an array of objects as input. Make sure panel ${escapedPanelIdentifier(
id
)} returns an array of objects.`;
}
static fromJSON(j: any) {
return new NotAnArrayOfObjectsError(j.targetPanelId);
}
}
export class InvalidDependentPanelError extends Error {
targetPanelId: number | string;
constructor(id: number | string) {
super();
this.name = 'InvalidDependentPanelError';
this.targetPanelId = id;
this.message = `A dependent panel's results are not valid. Did you run panel ${escapedPanelIdentifier(
id
)}?`;
}
static fromJSON(j: any) {
return new InvalidDependentPanelError(j.targetPanelId);
}
}
export class NoResultError extends Error {
constructor() {
super();
this.name = 'NoResultError';
this.message =
'This panel did not set any results. Did you call DM_setPanel($someValue)?';
}
}
export class NoConnectorError extends Error {
constructor() {
super();
this.name = 'NoConnectorError';
this.message = 'Without a data source this panel cannot be run.';
}
}
export class Cancelled extends Error {
constructor() {
super();
this.name = 'Cancelled';
this.message = 'Cancelled panel evaluation.';
}
}
export class UserError extends Error {
constructor(msg: string) {
super();
this.name = 'UserError';
this.message = msg;
}
static fromJSON(j: any) {
return new UserError(j.message);
}
}
export class UnsupportedError extends Error {
constructor(msg: string) {
super();
this.name = 'UnsupportedError';
this.message = msg;
}
static fromJSON(j: any) {
return new UnsupportedError(j.message);
}
}
export class BadTemplateError extends Error {
constructor(msg: string) {
super();
this.name = 'BadTemplateError';
this.message = msg;
}
static fromJSON(j: any) {
return new BadTemplateError(j.message);
}
}
export const EVAL_ERRORS = [
NotAnArrayOfObjectsError,
InvalidDependentPanelError,
NoResultError,
UnsupportedError,
UserError,
BadTemplateError,
NoConnectorError,
Cancelled,
];