Skip to content

Commit 8f551a0

Browse files
authored
feat: fix CI: fix TS18046 errors in catch blocks for strict mode compliance (#21)
1 parent e48735c commit 8f551a0

File tree

6 files changed

+20
-19
lines changed

6 files changed

+20
-19
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
runs-on: ubuntu-latest
5353
strategy:
5454
matrix:
55-
node: [^18, ^20]
55+
node: [^20]
5656
steps:
5757
- uses: actions/checkout@v3
5858

.github/workflows/platform_test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
node-version: [^18, ^20]
14+
node-version: [^20]
1515
steps:
1616
- uses: actions/checkout@v3
1717

@@ -37,7 +37,7 @@ jobs:
3737
strategy:
3838
fail-fast: false
3939
matrix:
40-
node-version: [^18, ^20]
40+
node-version: [^20]
4141
steps:
4242
- uses: actions/checkout@v3
4343

@@ -60,7 +60,7 @@ jobs:
6060
strategy:
6161
fail-fast: false
6262
matrix:
63-
node-version: [^18, ^20]
63+
node-version: [^20]
6464
steps:
6565
- uses: actions/checkout@v3
6666

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
}

src/util/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ function policyStringToArray(policy: string): string[][] {
213213

214214
function customIn(a: number | string, b: number | string): number {
215215
if ((b as any) instanceof Array) {
216-
return (((b as any) as Array<any>).includes(a) as unknown) as number;
216+
return (b as any as Array<any>).includes(a) as unknown as number;
217217
}
218-
return ((a in (b as any)) as unknown) as number;
218+
return (a in (b as any)) as unknown as number;
219219
}
220220

221221
function bracketCompatible(exp: string): string {

test/enforcer.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,9 @@ test('test ABAC multiple eval()', async () => {
573573
);
574574

575575
const e = await newEnforcer(m, policy);
576-
await testEnforce(e, 56, (98 as unknown) as string, 'read', true);
577-
await testEnforce(e, 23, (67 as unknown) as string, 'read', false);
578-
await testEnforce(e, 78, (34 as unknown) as string, 'read', false);
576+
await testEnforce(e, 56, 98 as unknown as string, 'read', true);
577+
await testEnforce(e, 23, 67 as unknown as string, 'read', false);
578+
await testEnforce(e, 78, 34 as unknown as string, 'read', false);
579579
});
580580

581581
test('TestEnforceSync', async () => {
@@ -645,9 +645,9 @@ test('test ABAC multiple eval()', async () => {
645645
);
646646

647647
const e = await newEnforcer(m, policy);
648-
await testEnforce(e, 56, (98 as unknown) as string, 'read', true);
649-
await testEnforce(e, 23, (67 as unknown) as string, 'read', false);
650-
await testEnforce(e, 78, (34 as unknown) as string, 'read', false);
648+
await testEnforce(e, 56, 98 as unknown as string, 'read', true);
649+
await testEnforce(e, 23, 67 as unknown as string, 'read', false);
650+
await testEnforce(e, 78, 34 as unknown as string, 'read', false);
651651
});
652652

653653
test('TestBatchEnforce', async () => {

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)