-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathErrorHandler.js
More file actions
1 lines (1 loc) · 2.35 KB
/
ErrorHandler.js
File metadata and controls
1 lines (1 loc) · 2.35 KB
1
define(function(require,exports){const Dialogs=brackets.getModule("widgets/Dialogs"),Mustache=brackets.getModule("thirdparty/mustache/mustache"),Metrics=brackets.getModule("utils/Metrics"),Strings=brackets.getModule("strings"),NotificationUI=brackets.getModule("widgets/NotificationUI"),Utils=require("src/Utils"),errorDialogTemplate=require("text!templates/git-error-dialog.html");function errorToString(err){return Utils.encodeSensitiveInformation(err.toString())}exports.isTimeout=function(err){return err instanceof Error&&(0===err.message.indexOf("cmd-execute-timeout")||0===err.message.indexOf("cmd-spawn-timeout"))},exports.equals=function(err,what){return err.toString().toLowerCase()===what.toLowerCase()},exports.contains=function(err,what){return-1!==err.toString().toLowerCase().indexOf(what.toLowerCase())},exports.matches=function(err,regExp){return err.toString().match(regExp)},exports.logError=function(err){const msg=err&&err.stack?err.stack:err;return Utils.consoleError("[brackets-git] "+msg),err},exports.showError=function(err,title,options={}){const dontStripError=options.dontStripError,errorMetric=options.errorMetric;if(err.__shown)return err;let errorBody,errorStack;if(exports.logError(err),"string"==typeof err?errorBody=err:err instanceof Error&&(errorBody=dontStripError?err.toString():errorToString(err),errorStack=err.stack||""),!errorBody||"[object Object]"===errorBody)try{errorBody=JSON.stringify(err,null,4)}catch(e){errorBody="Error can't be stringified by JSON.stringify"}if(errorBody=window.debugMode?`${errorBody}\n${errorStack}`:errorBody,options.useNotification)Metrics.countEvent(Metrics.EVENT_TYPE.GIT,"notifyErr",errorMetric||"Show"),NotificationUI.createToastFromTemplate(title,`<textarea readonly style="width: 200px; height: 200px; cursor: text; resize: none;">${errorBody}</textarea>`,{toastStyle:NotificationUI.NOTIFICATION_STYLES_CSS_CLASS.ERROR,dismissOnClick:!1,instantOpen:!0});else{Metrics.countEvent(Metrics.EVENT_TYPE.GIT,"dialogErr",errorMetric||"Show");const compiledTemplate=Mustache.render(errorDialogTemplate,{title:title,body:errorBody,Strings:Strings});Dialogs.showModalDialogUsingTemplate(compiledTemplate)}return"string"==typeof err&&(err=new Error(err)),err.__shown=!0,err},exports.toError=function(arg){if(arg instanceof Error)return arg;var err=new Error(arg);return err.match=function(){return arg.match.apply(arg,arguments)},err}});