Fix uncaught permission exception on upgrade/install daemon casuing main process death #5

This commit is contained in:
everoddandeven 2024-11-14 17:11:54 +01:00
parent 7a32bdc207
commit 546b810e3c
5 changed files with 46 additions and 2 deletions

View file

@ -541,7 +541,19 @@ const downloadFile = (url: string, destinationDir: string, onProgress: (progress
} }
const destination = `${destinationDir}/${finalFilename}`; const destination = `${destinationDir}/${finalFilename}`;
const file = fs.createWriteStream(destination); let file: fs.WriteStream;
try {
file = fs.createWriteStream(destination);
file.on('error', (error: Error) => {
console.log("file error: " + error);
reject(error);
});
}
catch (error: any) {
reject(error);
return;
}
const totalBytes = parseInt(response.headers['content-length'] || '0', 10); const totalBytes = parseInt(response.headers['content-length'] || '0', 10);
let downloadedBytes = 0; let downloadedBytes = 0;

View file

@ -141,6 +141,14 @@ export class DaemonService {
window.electronAPI.onMoneroClose((event: any, code: number) => { window.electronAPI.onMoneroClose((event: any, code: number) => {
console.debug(event); console.debug(event);
console.debug(code); console.debug(code);
if (code != 0) {
window.electronAPI.showNotification({
title: 'Daemon Error',
body: 'Monero daemon exited with code: ' + code,
closeButtonText: 'Dismiss'
});
}
this.onClose(); this.onClose();
}); });
@ -220,6 +228,7 @@ export class DaemonService {
private onClose(): void { private onClose(): void {
this.daemonRunning = false; this.daemonRunning = false;
this.starting = false;
this.stopping = false; this.stopping = false;
this.onDaemonStatusChanged.emit(false); this.onDaemonStatusChanged.emit(false);
this.onDaemonStopEnd.emit(); this.onDaemonStopEnd.emit();

View file

@ -0,0 +1,11 @@
export abstract class StringUtils {
public static replaceAll(value: string, oldValue: string, newValue: string): string {
let v = value;
while(v.includes(oldValue)) {
v = v.replace(oldValue, newValue);
}
return v;
}
}

View file

@ -0,0 +1 @@
export { StringUtils } from "./StringUtils";

View file

@ -5,6 +5,7 @@ import { SimpleBootstrapCard } from '../../shared/utils';
import { DaemonVersion } from '../../../common/DaemonVersion'; import { DaemonVersion } from '../../../common/DaemonVersion';
import { DaemonDataService, ElectronService, MoneroInstallerService } from '../../core/services'; import { DaemonDataService, ElectronService, MoneroInstallerService } from '../../core/services';
import { DaemonSettings } from '../../../common'; import { DaemonSettings } from '../../../common';
import { StringUtils } from '../../core/utils';
@Component({ @Component({
selector: 'app-version', selector: 'app-version',
@ -165,7 +166,17 @@ export class VersionComponent implements AfterViewInit {
console.error(error); console.error(error);
this.upgradeSuccess = false; this.upgradeSuccess = false;
this.upgradeError = `${error}`; let err = StringUtils.replaceAll(`${error}`, 'Error: ','');
if (err.includes('permission denied')) {
const settings = await this.daemonService.getSettings();
this.upgradeError = 'Cannot download monerod to ' + settings.downloadUpgradePath;
}
else {
this.upgradeError = err;
}
} }
} }
} }