Skip to content

Commit

Permalink
show insufficient space message for failed installation
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Feb 6, 2024
1 parent 4fb94d5 commit 6bbb93d
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/app/core/services/app-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class AppManagerService {
return;
} catch (e) {
// Never attempt to do default install, if we are reinstalling hbchannel
if (manifest.id === APP_ID_HBCHANNEL) {
if (e instanceof InstallError || manifest.id === APP_ID_HBCHANNEL) {
throw e;
}
}
Expand Down Expand Up @@ -206,6 +206,15 @@ export class AppManagerService {
filter(v => v)/* Only pick finish event */,
mergeMap(() => luna.unsubscribe()) /* Unsubscribe when done */,
catchError((e) => fromPromise(luna.unsubscribe().then(() => {
const match = e instanceof LunaResponseError && e.details?.match(/(-?\d+): +(\w+)/);
if (!match) {
throw e;
}
if (match[2] === 'FAILED_IPKG_INSTALL') {
if (match[1] === '-5') {
throw InstallError.insufficientSpace(e.details);
}
}
throw e;
})))/* Unsubscribe when failed, and throw the error */)
);
Expand All @@ -218,6 +227,11 @@ function mapAppinstalldResponse(v: LunaResponse, expectResult: string | RegExp):
if (resultValue.match(/FAILED/i)) {
let details = v['details'];
if (details && details.reason) {
if (details.reason === 'FAILED_IPKG_INSTALL') {
if (details.errorCode === -5) {
throw InstallError.insufficientSpace(details.reason);
}
}
throw new Error(`${details.errorCode}: ${details.reason}`);
}
throw new Error(resultValue);
Expand All @@ -231,3 +245,13 @@ function mapAppinstalldResponse(v: LunaResponse, expectResult: string | RegExp):
export interface InstallProgressHandler {
(progress?: number, statusText?: string): void;
}

export class InstallError extends Error {
constructor(message: string, public details: string) {
super(message);
}

static insufficientSpace(details: string): InstallError {
return new InstallError('Can\'t install because of insufficient space', details);
}
}

0 comments on commit 6bbb93d

Please sign in to comment.