Skip to content

Commit 1d48287

Browse files
authored
Merge pull request #3430 from SeedCompany/bugfix/pnp-unknown-sheet
2 parents c70f288 + a3b11ce commit 1d48287

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/common/xlsx.util.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
utils,
1111
type WorkSheet,
1212
} from 'xlsx';
13+
import { NotFoundException } from './exceptions';
1314
import { CalendarDate } from './temporal';
1415

1516
export class WorkBook {
@@ -56,8 +57,22 @@ export class WorkBook {
5657
@Once() private get namedRanges(): Record<string, Range> {
5758
const rawList = this.book.Workbook?.Names ?? [];
5859
return mapEntries(rawList, ({ Ref: ref, Name: name }, { SKIP }) => {
59-
const matched = /^'?([^']+)'?!([$\dA-Z]+(?::[$\dA-Z]+)?)$/.exec(ref);
60-
return matched ? [name, this.sheet(matched[1]).range(matched[2])] : SKIP;
60+
const matched =
61+
/^(?:\[\d+])?'?([^']+)'?!([$\dA-Z]+(?::[$\dA-Z]+)?)$/.exec(ref);
62+
if (!matched) {
63+
return SKIP;
64+
}
65+
const [_, sheetName, rangeStr] = matched;
66+
try {
67+
const range = this.sheet(sheetName).range(rangeStr);
68+
return [name, range];
69+
} catch (e) {
70+
// Skip ranges that correspond to nonexistent sheets
71+
if (e instanceof NotFoundException) {
72+
return SKIP;
73+
}
74+
throw e;
75+
}
6176
}).asRecord;
6277
}
6378
}
@@ -83,7 +98,7 @@ export class Sheet {
8398
this.workbook = this.book.book;
8499
this.sheet = this.workbook.Sheets[this.name];
85100
if (!this.sheet) {
86-
throw new Error(`Cannot find ${this.name} sheet`);
101+
throw new NotFoundException(`Cannot find ${this.name} sheet`);
87102
}
88103
}
89104
nonEnumerable(this, 'workbook' as any, 'sheet' as any);

src/components/product/pnp-product-sync.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class PnpProductSyncService {
6767
result,
6868
);
6969
} catch (e) {
70-
this.logger.warning(e.message, {
70+
this.logger.error(e.message, {
7171
id: pnp.id,
7272
exception: e,
7373
});

0 commit comments

Comments
 (0)