Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Commit

Permalink
add error message back when daemon crashes before 10 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Sep 18, 2019
1 parent cb6b7b2 commit 28907d2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,12 @@ ipcMain.on('launchDaemon', async(ev, config) => {
});

daemon.on('exit', (code, stats) => {
log.info(`daemon exited after ${Math.floor((Date.now() - stats.start) / 1000)} seconds with exit code ${code}`);
const runtime = Math.floor((Date.now() - stats.start) / 1000);

if (runtime < 10)
win.webContents.send('daemonError', -1, stats);

log.info(`daemon exited after ${runtime} seconds with exit code ${code}`);

if (stats.stderr && stats.stderr.trim().length > 0)
log.error('daemon stderr', stats.stderr);
Expand Down
14 changes: 7 additions & 7 deletions src/data/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ async function onDaemonLoaded(ev, stats) {
}
}

function onDaemonCritical(ev, error) {
function onDaemonCritical(ev, code, stats) {
try {
Store.dispatch('setCriticalError', error);
const runtime = Math.floor((Date.now() - stats.start) / 1000);

Store.dispatch('setCriticalError', `Daemon crashed in ${runtime} seconds. Unable to start Sia. Please check logs for more information`);
} catch (ex) {
log.error('onDaemonCritical', ex.message);
}
}

export function launch(config) {
ipcRenderer.removeListener('daemonUpdate', onDaemonUpdate);
ipcRenderer.removeListener('daemonLoaded', onDaemonLoaded);
ipcRenderer.removeListener('daemonError', onDaemonCritical);

export function attachIPC() {
ipcRenderer.on('daemonUpdate', onDaemonUpdate);
ipcRenderer.on('daemonLoaded', onDaemonLoaded);
ipcRenderer.on('daemonError', onDaemonCritical);
}

export function launch(config) {
ipcRenderer.send('launchDaemon', config);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import App from './App.vue';
import router from './router';
import store from './store';
import { readConfig, checkSiaDataFolders, getConsensusPath } from '@/utils';
import { attachIPC } from '@/data/daemon';

import { library } from '@fortawesome/fontawesome-svg-core';
import { faFilter, faFastForward, faCopy, faSave, faBell, faBullhorn, faInfo, faFolder, faExternalLinkAlt, faWifi, faRedo, faCheckCircle, faWallet, faTimes,
Expand All @@ -26,6 +27,7 @@ process.on('unhandledRejection', error => {
});

async function init() {
attachIPC();
document.body.classList.add(process.platform);

try {
Expand Down
16 changes: 15 additions & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function mkdirIfNotExist(path) {
await fs.mkdir(path, {
recursive: true
});
} catch (ex) {}
} catch (ex) { }
}

export async function writeConfig(config) {
Expand All @@ -51,6 +51,20 @@ export async function readConfig() {
return config;
}

export function getLogPath() {
const appName = app.getName(),
homePath = app.getPath('home');

switch (process.platform) {
case 'darwin':
return path.join(homePath, `Library/Logs/${appName}/log.log`);
case 'win32':
return path.join(homePath, `AppData/Roaming/${appName}/log.log`);
default:
return path.join(homePath, `.config/${appName}/log.log`);
}
}

export function getConsensusPath(loc) {
if (loc)
return loc;
Expand Down
8 changes: 7 additions & 1 deletion src/views/setup/ReviewStep.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export default {
daemonLoaded: state => state.hostDaemon.loaded,
daemonLoadingModule: state => state.hostDaemon.currentModule,
daemonLoadPercent: state => state.hostDaemon.loadPercent,
daemonManaged: state => state.hostDaemon.managed
daemonManaged: state => state.hostDaemon.managed,
criticalError: state => state.criticalError
})
},
data() {
Expand Down Expand Up @@ -99,6 +100,11 @@ export default {
createWallet: !this.walletUnlocked && !this.walletEncrypted
});
}
},
watch: {
criticalError(val) {
this.error = val;
}
}
};
</script>

0 comments on commit 28907d2

Please sign in to comment.