Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: friendlier error message when another daemon is running #541

Merged
merged 1 commit into from
Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default [
{
find: [
'ipfs daemon is running',
'already locked'
],
title: 'IPFS is already running',
message: 'Please stop your IPFS daemon before running Station.'
}
]
36 changes: 27 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {join} from 'path'
import config, {logger, fileHistory, logoIpfsIce, logoIpfsBlack} from './config'
import {dialog, ipcMain, shell, app} from 'electron'

import knownErrors from './errors'
import StatsPoller from './utils/stats-poller'

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
Expand All @@ -35,6 +36,26 @@ if (config.isProduction) {
require('electron-debug')()
}

function handleKnownErrors (e) {
const msg = e.toString()

const error = knownErrors.find((error) => {
return error.find.find((term) => {
return msg.includes(term)
})
})

if (error === undefined) {
throw e
} else {
dialog.showErrorBox(
error.title,
error.message
)
process.exit(1)
}
}

// Local Variables

let poller = null
Expand Down Expand Up @@ -92,7 +113,10 @@ function onStartDaemon (node) {
send('node-status', 'starting')

node.startDaemon((err, ipfsNode) => {
if (err) throw err
if (err) {
handleKnownErrors(err)
return
}

poller = new StatsPoller(ipfsNode, logger)

Expand Down Expand Up @@ -139,17 +163,11 @@ function onStopDaemon (node, done) {

function onWillQuit (node, event) {
logger.info('Shutting down application')
event.preventDefault()

if (IPFS == null) return

// TODO: Try waiting for the daemon to properly
// shut down before we actually quit

event.preventDefault()

const quit = mb.app.quit.bind(mb.app)
onStopDaemon(node, quit)
setTimeout(quit, 1000)
onStopDaemon(node, mb.app.quit.bind(mb.app))
}

function startTray (node) {
Expand Down