From 67f7a7e5a5cfc1822a3193627a1d1687322b4f60 Mon Sep 17 00:00:00 2001 From: Johnathan Howell Date: Tue, 14 Mar 2017 19:38:34 -0400 Subject: [PATCH] display siad's stderr on loadingscreen if load fails --- css/general.css | 2 +- index.html | 2 +- js/rendererjs/loadingScreen.js | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/css/general.css b/css/general.css index d1787487..64cfc004 100644 --- a/css/general.css +++ b/css/general.css @@ -274,7 +274,7 @@ html,body { height: 100%; text-align: center; - font-size: 50px; + font-size: 35px; background-color: #fff; opacity: .5; } diff --git a/index.html b/index.html index feffef46..5f43b289 100644 --- a/index.html +++ b/index.html @@ -14,7 +14,7 @@

- +
diff --git a/js/rendererjs/loadingScreen.js b/js/rendererjs/loadingScreen.js index bcb777d1..48e74436 100644 --- a/js/rendererjs/loadingScreen.js +++ b/js/rendererjs/loadingScreen.js @@ -14,12 +14,14 @@ const fs = remote.require('fs') const config = remote.getGlobal('config') const siadConfig = config.attr('siad') +const spinner = document.getElementById('loading-spinner') const overlay = document.getElementsByClassName('overlay')[0] const overlayText = overlay.getElementsByClassName('centered')[0].getElementsByTagName('p')[0] overlayText.textContent = 'Loading Sia...' const showError = (error) => { overlayText.textContent = 'A Sia-UI error has occured: ' + error + spinner.style.display = 'none' } // startUI starts a Sia UI instance using the given welcome message. @@ -56,6 +58,17 @@ const checkSiaPath = () => new Promise((resolve) => { }) }) +// unexpectedExitHandler handles an unexpected siad exit, displaying the error +// piped to siad-output.log. +const unexpectedExitHandler = () => { + try { + const errorMsg = fs.readFileSync(Path.join(siadConfig.datadir, 'siad-output.log')) + showError('Siad unexpectedly exited. Error log: ' + errorMsg) + } catch (e) { + showError('Siad unexpectedly exited.') + } +} + // Check if Siad is already running on this host. // If it is, start the UI and display a welcome message to the user. // Otherwise, start a new instance of Siad using config.js. @@ -99,8 +112,8 @@ export default async function loadingScreen(initUI) { 'api-addr': siadConfig.address, }) siadProcess.on('error', (e) => showError('Siad couldnt start: ' + e.toString())) - siadProcess.on('close', () => showError('Siad unexpectedly closed.')) - siadProcess.on('exit', () => showError('Siad unexpectedly exited.')) + siadProcess.on('close', unexpectedExitHandler) + siadProcess.on('exit', unexpectedExitHandler) window.siadProcess = siadProcess } catch (e) { showError(e.toString())