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

feat(ux): better error messages #1421

Merged
merged 3 commits into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,13 @@
"runGarbageCollectorDone": {
"title": "Garbage collector",
"message": "The garbage collector ran successfully."
},
"moveRepositoryFailed": {
"title": "Move repository",
"message": "Could not move the repository from { currDir } to { newDir }."
hacdias marked this conversation as resolved.
Show resolved Hide resolved
},
"cantAddIpfsToPath": {
"title": "IPFS on PATH",
hacdias marked this conversation as resolved.
Show resolved Hide resolved
"message": "Could not add IPFS to the PATH."
hacdias marked this conversation as resolved.
Show resolved Hide resolved
}
}
19 changes: 16 additions & 3 deletions src/dialogs/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ function criticalErrorDialog (e) {
app.exit(1)
}

function recoverableErrorDialog (e) {
const option = dialog({
// Shows a recoverable error dialog with the default title and message.
// Passing an options object alongside the error can be used to override
// the title and message.
function recoverableErrorDialog (e, options = {}) {
const cfg = {
title: i18n.t('recoverableErrorDialog.title'),
message: i18n.t('recoverableErrorDialog.message'),
type: 'error',
Expand All @@ -54,7 +57,17 @@ function recoverableErrorDialog (e) {
i18n.t('reportTheError'),
i18n.t('openLogs')
]
})
}

if (options.title) {
cfg.title = options.title
}

if (options.message) {
cfg.message = options.message
}

const option = dialog(cfg)

if (option === 1) {
shell.openExternal(`https://github.com/ipfs-shipyard/ipfs-desktop/issues/new?body=${encodeURI(issueTemplate(e))}`)
Expand Down
6 changes: 5 additions & 1 deletion src/ipfs-on-path/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { join } = require('path')
const i18n = require('i18next')
const which = require('which')
const { execFile } = require('child_process')
const createToggler = require('../create-toggler')
Expand Down Expand Up @@ -53,7 +54,10 @@ async function runWindows (script, { failSilently }) {
logger.error(`[ipfs on path] ${err.toString()}`)

if (!failSilently) {
recoverableErrorDialog(err)
recoverableErrorDialog(err, {
title: i18n.t('cantAddIpfsToPath.title'),
message: i18n.t('cantAddIpfsToPath.message')
})
}

return resolve(false)
Expand Down
5 changes: 4 additions & 1 deletion src/move-repository-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ module.exports = function ({ stopIpfs, startIpfs }) {
logger.info(`[move repository] moved from ${currDir} to ${newDir}`)
} catch (err) {
logger.error(`[move repository] ${err.toString()}`)
return recoverableErrorDialog(err)
return recoverableErrorDialog(err, {
title: i18n.t('moveRepositoryFailed.title'),
message: i18n.t('moveRepositoryFailed.message', { currDir, newDir })
})
}

config.path = newDir
Expand Down