Skip to content

Commit 771840c

Browse files
committed
fix(plugins): refine error and success handling during plugin installation
- Updated the `UnraidPluginsService` to ensure that error and success handling for plugin installations only occurs when the operation status is RUNNING. - Added checks in the `handleFailure` and `handleSuccess` methods to prevent state changes if the operation is not in progress. - This change improves the reliability of the plugin installation process by preventing unintended state updates after the operation has completed or failed.
1 parent a2d9d7a commit 771840c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

api/src/unraid-api/graph/resolvers/unraid-plugins/unraid-plugins.service.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,16 @@ export class UnraidPluginsService {
8383
}
8484

8585
child.on('error', (error) => {
86-
this.handleFailure(operation, error);
86+
if (operation.status === PluginInstallStatus.RUNNING) {
87+
this.handleFailure(operation, error);
88+
}
8789
});
8890

8991
child.on('close', (code) => {
92+
if (operation.status !== PluginInstallStatus.RUNNING) {
93+
return;
94+
}
95+
9096
if (code === 0) {
9197
this.handleSuccess(operation);
9298
} else {
@@ -150,6 +156,10 @@ export class UnraidPluginsService {
150156
}
151157

152158
private handleSuccess(operation: OperationState) {
159+
if (operation.status !== PluginInstallStatus.RUNNING) {
160+
return;
161+
}
162+
153163
const timestamp = new Date();
154164
operation.status = PluginInstallStatus.SUCCEEDED;
155165
operation.finishedAt = timestamp;
@@ -168,6 +178,10 @@ export class UnraidPluginsService {
168178
}
169179

170180
private handleFailure(operation: OperationState, error: unknown) {
181+
if (operation.status !== PluginInstallStatus.RUNNING) {
182+
return;
183+
}
184+
171185
const timestamp = new Date();
172186
operation.status = PluginInstallStatus.FAILED;
173187
operation.finishedAt = timestamp;

0 commit comments

Comments
 (0)