From dbeb56daa9b521a67214ca4a4080510b7843b88d Mon Sep 17 00:00:00 2001 From: Ian Bicking Date: Fri, 2 Jun 2017 13:42:56 -0500 Subject: [PATCH] Fix #2957, make empty selections report an error Previously they were creating empty data: URLs and causing server rejection --- addon/webextension/background/senderror.js | 7 ++++++- addon/webextension/selector/shooter.js | 8 ++++++++ docs/error-handling.md | 2 ++ locales/en-US/webextension.properties | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/addon/webextension/background/senderror.js b/addon/webextension/background/senderror.js index 83b16069f3..0983c1dcbf 100644 --- a/addon/webextension/background/senderror.js +++ b/addon/webextension/background/senderror.js @@ -37,6 +37,9 @@ this.senderror = (function() { MY_SHOTS: { title: browser.i18n.getMessage("selfScreenshotErrorTitle") }, + EMPTY_SELECTION: { + title: browser.i18n.getMessage("emptySelectionErrorTitle") + }, generic: { title: browser.i18n.getMessage("genericErrorTitle"), info: browser.i18n.getMessage("genericErrorDetails"), @@ -112,7 +115,9 @@ this.senderror = (function() { if (!errorObj.noPopup) { exports.showError(errorObj); } - exports.reportError(errorObj); + if (!errorObj.noReport) { + exports.reportError(errorObj); + } }); return exports; diff --git a/addon/webextension/selector/shooter.js b/addon/webextension/selector/shooter.js index cdb20e05a0..cf23709a83 100644 --- a/addon/webextension/selector/shooter.js +++ b/addon/webextension/selector/shooter.js @@ -67,6 +67,14 @@ this.shooter = (function() { // eslint-disable-line no-unused-vars // isSaving indicates we're aleady in the middle of saving // we use a timeout so in the case of a failure the button will // still start working again + if (Math.floor(selectedPos.left) == Math.floor(selectedPos.right) || + Math.floor(selectedPos.top) == Math.floor(selectedPos.bottom)) { + let exc = new Error("Empty selection"); + exc.popupMessage = "EMPTY_SELECTION"; + exc.noReport = true; + catcher.unhandled(exc); + return; + } const uicontrol = global.uicontrol; let deactivateAfterFinish = true; if (isSaving) { diff --git a/docs/error-handling.md b/docs/error-handling.md index 118c6314c2..d7336eb0dc 100644 --- a/docs/error-handling.md +++ b/docs/error-handling.md @@ -105,3 +105,5 @@ Note that any information will be serialized as JSON. Specifically `undefined` If you add `exc.popupMessage = "Something happened"` then that detail will be added. Be careful about localization here. Add `exc.noPopup = true` if you don't want the user notified about the error (but the error will still be sent to Sentry). + +Add `exc.noReport = true` if you don't want the error reported to Sentry. diff --git a/locales/en-US/webextension.properties b/locales/en-US/webextension.properties index 4d7112fa20..d0b5b3e475 100644 --- a/locales/en-US/webextension.properties +++ b/locales/en-US/webextension.properties @@ -27,6 +27,8 @@ loginErrorDetails = We couldn’t save your shot because there is a problem with unshootablePageErrorTitle = We can’t screenshot this page. unshootablePageErrorDetails = This isn’t a standard Web page, so you can’t take a screenshot of it. selfScreenshotErrorTitle = You can’t take a shot of a Firefox Screenshots page! +# Fired when someone makes a zero-width or zero-height selection +emptySelectionErrorTitle = Your selection is too small genericErrorTitle = Whoa! Firefox Screenshots went haywire. genericErrorDetails = We’re not sure what just happened. Care to try again or take a shot of a different page? # Section for onboarding strings