Skip to content

Commit 076d1cf

Browse files
committed
fix: add instanceof Error checks to fix TS18046 errors
Signed-off-by: GitHub Copilot <noreply@github.com>
1 parent dd4e1f6 commit 076d1cf

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/internalEnforcer.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class InternalEnforcer extends CoreEnforcer {
3333
try {
3434
await this.adapter.addPolicy(sec, ptype, rule);
3535
} catch (e) {
36-
if (e.message !== 'not implemented') {
36+
if (e instanceof Error && e.message !== 'not implemented') {
3737
throw e;
3838
}
3939
}
@@ -70,7 +70,7 @@ export class InternalEnforcer extends CoreEnforcer {
7070
try {
7171
await (this.adapter as BatchAdapter).addPolicies(sec, ptype, rules);
7272
} catch (e) {
73-
if (e.message !== 'not implemented') {
73+
if (e instanceof Error && e.message !== 'not implemented') {
7474
throw e;
7575
}
7676
}
@@ -108,7 +108,7 @@ export class InternalEnforcer extends CoreEnforcer {
108108
try {
109109
await (this.adapter as UpdatableAdapter).updatePolicy(sec, ptype, oldRule, newRule);
110110
} catch (e) {
111-
if (e.message !== 'not implemented') {
111+
if (e instanceof Error && e.message !== 'not implemented') {
112112
throw e;
113113
}
114114
}
@@ -144,7 +144,7 @@ export class InternalEnforcer extends CoreEnforcer {
144144
try {
145145
await this.adapter.removePolicy(sec, ptype, rule);
146146
} catch (e) {
147-
if (e.message !== 'not implemented') {
147+
if (e instanceof Error && e.message !== 'not implemented') {
148148
throw e;
149149
}
150150
}
@@ -179,7 +179,7 @@ export class InternalEnforcer extends CoreEnforcer {
179179
try {
180180
await (this.adapter as BatchAdapter).removePolicies(sec, ptype, rules);
181181
} catch (e) {
182-
if (e.message !== 'not implemented') {
182+
if (e instanceof Error && e.message !== 'not implemented') {
183183
throw e;
184184
}
185185
}
@@ -212,7 +212,7 @@ export class InternalEnforcer extends CoreEnforcer {
212212
try {
213213
await this.adapter.removeFilteredPolicy(sec, ptype, fieldIndex, ...fieldValues);
214214
} catch (e) {
215-
if (e.message !== 'not implemented') {
215+
if (e instanceof Error && e.message !== 'not implemented') {
216216
throw e;
217217
}
218218
}

test/model/model.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ test('TestLoadModelFromConfig', (done) => {
5656
}
5757

5858
if (e instanceof Error) {
59+
const errorMessage = e.message;
5960
requiredSections.forEach((n) => {
60-
if (!e.message.includes(n)) {
61+
if (!errorMessage.includes(n)) {
6162
throw new Error(`section name: ${sectionNameMap[n]} should be in message`);
6263
}
6364
});

0 commit comments

Comments
 (0)