Skip to content

Commit e1419e0

Browse files
committed
Attempt to handle UBT files uploaded to PnP spots better
Render a specific error & don't log this as a problem for devs.
1 parent c138c58 commit e1419e0

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/components/pnp/pnp.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { WorkBook } from '~/common/xlsx.util';
1+
import { InputException, NotFoundException } from '~/common';
2+
import { type Sheet, WorkBook } from '~/common/xlsx.util';
23
import { type Downloadable, type FileVersion } from '../file/dto';
34
import { PlanningSheet } from './planning-sheet';
45
import { ProgressSheet } from './progress-sheet';
@@ -28,10 +29,26 @@ export class Pnp {
2829
}
2930

3031
get planning() {
31-
return this.workbook.sheet<PlanningSheet>('Planning');
32+
return this.sheet<PlanningSheet>('Planning');
3233
}
3334

3435
get progress() {
35-
return this.workbook.sheet<ProgressSheet>('Progress');
36+
return this.sheet<ProgressSheet>('Progress');
37+
}
38+
39+
protected sheet<TSheet extends Sheet>(name: string): TSheet {
40+
try {
41+
return this.workbook.sheet(name);
42+
} catch (e) {
43+
if (e instanceof NotFoundException && this.fileName?.match(/\bUBT\b/)) {
44+
throw new NotPnPFile(
45+
`It appears you are uploading a _budget_ excel file, not a _PnP_ file.`,
46+
e,
47+
);
48+
}
49+
throw e;
50+
}
3651
}
3752
}
53+
54+
export class NotPnPFile extends InputException {}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { DateTime } from 'luxon';
77
import { DateInterval, type ID } from '~/common';
88
import { ILogger, Logger, ResourceLoader } from '~/core';
99
import { type Downloadable, type FileVersion } from '../file/dto';
10+
import { NotPnPFile } from '../pnp';
1011
import {
1112
type PnpExtractionResult,
1213
PnpProblemType,
@@ -67,10 +68,12 @@ export class PnpProductSyncService {
6768
result,
6869
);
6970
} catch (e) {
70-
this.logger.error(e.message, {
71-
id: pnp.id,
72-
exception: e,
73-
});
71+
if (!(e instanceof NotPnPFile)) {
72+
this.logger.error(e.message, {
73+
id: pnp.id,
74+
exception: e,
75+
});
76+
}
7477
return [];
7578
}
7679
if (productRows.length === 0) {

0 commit comments

Comments
 (0)