Skip to content

Commit 079fa99

Browse files
authored
GLSP-1483: Stop progress on model loading error (#104)
Update `RequestModelActionHandler` to ensure that pending progresses are properly cancelled/ended if an error occured during loading In addition, make progress monitor arg in `reportModelLoadingFinished` optional. This covers the case where an adopter overrides the `reportModelLoading` method and opts for no progress reporting Fixes: eclipse-glsp/glsp#1485
1 parent 6064bdb commit 079fa99

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

packages/server/src/common/features/model/request-model-action-handler.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,16 @@ export class RequestModelActionHandler implements ActionHandler {
5454

5555
const progress = this.reportModelLoading('Model loading in progress');
5656

57-
if (isReconnecting) {
58-
await this.handleReconnect(action);
59-
} else {
60-
await this.sourceModelStorage.loadSourceModel(action);
57+
try {
58+
if (isReconnecting) {
59+
await this.handleReconnect(action);
60+
} else {
61+
await this.sourceModelStorage.loadSourceModel(action);
62+
}
63+
} catch (err) {
64+
this.handleModelLoadingError(err, progress);
6165
}
66+
6267
this.reportModelLoadingFinished(progress);
6368

6469
return this.submissionHandler.submitInitialModel(action);
@@ -75,13 +80,20 @@ export class RequestModelActionHandler implements ActionHandler {
7580
}
7681
}
7782

78-
protected reportModelLoading(message: string): ProgressMonitor {
83+
protected reportModelLoading(message: string): ProgressMonitor | undefined {
7984
this.actionDispatcher.dispatch(StatusAction.create(message, { severity: 'INFO' }));
8085
return this.progressService.start(message);
8186
}
8287

83-
protected reportModelLoadingFinished(monitor: ProgressMonitor): void {
88+
protected reportModelLoadingFinished(monitor?: ProgressMonitor): void {
8489
this.actionDispatcher.dispatch(StatusAction.create('', { severity: 'NONE' }));
85-
monitor.end();
90+
monitor?.end();
91+
}
92+
93+
protected handleModelLoadingError(error: unknown, monitor?: ProgressMonitor): void {
94+
// In case of an error we end progress reporting and rethrow the error so
95+
// that it can be handled by the default error handler
96+
monitor?.end();
97+
throw error;
8698
}
8799
}

0 commit comments

Comments
 (0)