From ace6cf4c9ec1e40e3e970800e7dbbe84a78163a7 Mon Sep 17 00:00:00 2001 From: Halla Moore Date: Tue, 13 Dec 2016 18:16:51 -0800 Subject: [PATCH] feat(showDetails): Allow a "Show Details" option on error dialogs Summary: Pass in more details on sending errors, so that they can be viewed more easily by clicking "Show Details", rather than having to check the worker window console. Test Plan: tested locally Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D3505 --- internal_packages/composer/lib/main.jsx | 12 ++------ src/K2 | 2 +- src/flux/stores/draft-store.es6 | 10 +++---- src/flux/tasks/send-draft-task.es6 | 1 + src/nylas-env.coffee | 37 ++++++++++++++++++++----- 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/internal_packages/composer/lib/main.jsx b/internal_packages/composer/lib/main.jsx index 288723e17..febba4cb5 100644 --- a/internal_packages/composer/lib/main.jsx +++ b/internal_packages/composer/lib/main.jsx @@ -58,7 +58,7 @@ class ComposerWithWindowProps extends React.Component { NylasEnv.displayWindow(); if (this.state.errorMessage) { - this._showInitialErrorDialog(this.state.errorMessage); + this._showInitialErrorDialog(this.state.errorMessage, this.state.errorDetail); } // This will start loading the rest of the composer's plugins. This @@ -87,18 +87,12 @@ class ComposerWithWindowProps extends React.Component { ); } - _showInitialErrorDialog(msg) { - const dialog = remote.dialog; + _showInitialErrorDialog(msg, detail) { // We delay so the view has time to update the restored draft. If we // don't delay the modal may come up in a state where the draft looks // like it hasn't been restored or has been lost. _.delay(() => { - dialog.showMessageBox(remote.getCurrentWindow(), { - type: 'warning', - buttons: ['Okay'], - message: "Error", - detail: msg, - }); + NylasEnv.showErrorDialog({title: 'Error', message: msg}, {detail: detail}) }, 100); } } diff --git a/src/K2 b/src/K2 index 67d1e14e6..d34cfa86b 160000 --- a/src/K2 +++ b/src/K2 @@ -1 +1 @@ -Subproject commit 67d1e14e60fe204faf56622de38f2124ac7ffe24 +Subproject commit d34cfa86b0a09d90189cc1f5237c26123fd5b6ab diff --git a/src/flux/stores/draft-store.es6 b/src/flux/stores/draft-store.es6 index 0def2f5a0..c64a68227 100644 --- a/src/flux/stores/draft-store.es6 +++ b/src/flux/stores/draft-store.es6 @@ -425,7 +425,7 @@ class DraftStore extends NylasStore { this.trigger(draftClientId); } - _onSendDraftFailed = ({draftClientId, threadId, errorMessage}) => { + _onSendDraftFailed = ({draftClientId, threadId, errorMessage, errorDetail}) => { this._draftsSending[draftClientId] = false; this.trigger(draftClientId); if (NylasEnv.isMainWindow()) { @@ -436,17 +436,17 @@ class DraftStore extends NylasStore { // We also need to delay because the old draft window needs to fully // close. It takes windows currently (June 2016) 100ms to close by setTimeout(() => { - this._notifyUserOfError({draftClientId, threadId, errorMessage}); + this._notifyUserOfError({draftClientId, threadId, errorMessage, errorDetail}); }, 300); } } - _notifyUserOfError({draftClientId, threadId, errorMessage}) { + _notifyUserOfError({draftClientId, threadId, errorMessage, errorDetail}) { const focusedThread = FocusedContentStore.focused('thread'); if (threadId && focusedThread && focusedThread.id === threadId) { - NylasEnv.showErrorDialog(errorMessage); + NylasEnv.showErrorDialog(errorMessage, {detail: errorDetail}); } else { - Actions.composePopoutDraft(draftClientId, {errorMessage}); + Actions.composePopoutDraft(draftClientId, {errorMessage, errorDetail}); } } } diff --git a/src/flux/tasks/send-draft-task.es6 b/src/flux/tasks/send-draft-task.es6 index 8d8e41086..7a01fde32 100644 --- a/src/flux/tasks/send-draft-task.es6 +++ b/src/flux/tasks/send-draft-task.es6 @@ -256,6 +256,7 @@ export default class SendDraftTask extends BaseDraftTask { threadId: this.draft.threadId, draftClientId: this.draft.clientId, errorMessage: message, + errorDetail: err.message + (err.error ? err.error.stack : '') + err.stack, }); } NylasEnv.reportError(err); diff --git a/src/nylas-env.coffee b/src/nylas-env.coffee index 0acd30f11..e138f0795 100644 --- a/src/nylas-env.coffee +++ b/src/nylas-env.coffee @@ -865,7 +865,7 @@ class NylasEnvConstructor options.title ?= 'Save File' callback(remote.dialog.showSaveDialog(@getCurrentWindow(), options)) - showErrorDialog: (messageData, {showInMainWindow}={}) -> + showErrorDialog: (messageData, {showInMainWindow, detail}={}) -> if _.isString(messageData) or _.isNumber(messageData) message = messageData title = "Error" @@ -879,12 +879,35 @@ class NylasEnvConstructor if showInMainWindow winToShow = remote.getGlobal('application').getMainWindow() - remote.dialog.showMessageBox winToShow, { - type: 'warning' - buttons: ['Okay'], - message: title - detail: message - } + if !detail + remote.dialog.showMessageBox winToShow, { + type: 'warning' + buttons: ['Okay'], + message: title + detail: message + } + else + withoutDetails = -> + remote.dialog.showMessageBox winToShow, { + type: 'warning' + buttons: ['Okay', 'Show Details'], + message: title + detail: message + }, (buttonIndex) -> + if buttonIndex == 1 + withDetails() + + withDetails = -> + remote.dialog.showMessageBox winToShow, { + type: 'warning' + buttons: ['Okay', 'Hide Details'], + message: title + detail: message + '\n\nDetails\n‾‾‾‾‾‾‾‾‾‾\n' + detail + }, (buttonIndex) -> + if buttonIndex == 1 + withoutDetails() + + withoutDetails() # Delegate to the browser's process fileListCache fileListCache: ->