Skip to content

Commit 791d5d3

Browse files
committed
fix: bugsnag error logs in git when staging fails is an expected error
1 parent 97512dd commit 791d5d3

File tree

5 files changed

+59
-18
lines changed

5 files changed

+59
-18
lines changed

src/extensions/default/Git/src/ErrorHandler.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ define(function (require, exports) {
44
Mustache = brackets.getModule("thirdparty/mustache/mustache"),
55
Metrics = brackets.getModule("utils/Metrics"),
66
Strings = brackets.getModule("strings"),
7+
NotificationUI = brackets.getModule("widgets/NotificationUI"),
78
Utils = require("src/Utils"),
89
errorDialogTemplate = require("text!templates/git-error-dialog.html");
910

@@ -40,7 +41,7 @@ define(function (require, exports) {
4041
*
4142
* @param err
4243
* @param title
43-
* @param {dontStripError: boolean, errorMetric: string} options
44+
* @param {dontStripError: boolean, errorMetric: string, useNotification: boolean} options
4445
*/
4546
exports.showError = function (err, title, options = {}) {
4647
const dontStripError = options.dontStripError;
@@ -67,14 +68,25 @@ define(function (require, exports) {
6768
errorBody = "Error can't be stringified by JSON.stringify";
6869
}
6970
}
71+
errorBody = window.debugMode ? `${errorBody}\n${errorStack}` : errorBody;
72+
73+
if(options.useNotification){
74+
NotificationUI.createToastFromTemplate(title,
75+
`<textarea readonly style="width: 200px; height: 200px; cursor: text; resize: none;">${errorBody}</textarea>`, {
76+
toastStyle: NotificationUI.NOTIFICATION_STYLES_CSS_CLASS.ERROR,
77+
dismissOnClick: false,
78+
instantOpen: true
79+
});
80+
} else {
81+
const compiledTemplate = Mustache.render(errorDialogTemplate, {
82+
title: title,
83+
body: errorBody,
84+
Strings: Strings
85+
});
86+
87+
Dialogs.showModalDialogUsingTemplate(compiledTemplate);
88+
}
7089

71-
var compiledTemplate = Mustache.render(errorDialogTemplate, {
72-
title: title,
73-
body: window.debugMode ? `${errorBody}\n${errorStack}` : errorBody,
74-
Strings: Strings
75-
});
76-
77-
Dialogs.showModalDialogUsingTemplate(compiledTemplate);
7890
if (typeof err === "string") { err = new Error(err); }
7991
err.__shown = true;
8092
return err;

src/extensions/default/Git/src/Panel.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,15 +1050,23 @@ define(function (require, exports) {
10501050

10511051
lastCheckOneClicked = file;
10521052

1053+
let stagePromise;
10531054
if (isChecked) {
1054-
Git.stage(file, status === Git.FILE_STATUS.DELETED).then(function () {
1055-
Git.status();
1055+
stagePromise = Git.stage(file, status === Git.FILE_STATUS.DELETED).then(function () {
1056+
return Git.status();
10561057
});
10571058
} else {
1058-
Git.unstage(file).then(function () {
1059-
Git.status();
1059+
stagePromise = Git.unstage(file).then(function () {
1060+
return Git.status();
10601061
});
10611062
}
1063+
stagePromise.catch((err)=>{
1064+
ErrorHandler.showError(err, Strings.ERROR_STAGE_FAILED, {
1065+
dontStripError: true,
1066+
errorMetric: "stageOne",
1067+
useNotification: true
1068+
});
1069+
});
10621070
})
10631071
.on("dblclick", ".check-one", function (e) {
10641072
e.stopPropagation();
@@ -1244,9 +1252,19 @@ define(function (require, exports) {
12441252
return Git.stageAll().then(function () {
12451253
return Git.status();
12461254
}).catch((err)=>{
1247-
console.error(err);
1248-
// rethrowing with stripped git error details as it may have sensitive info
1249-
throw new Error("Error stage all by checkbox in git panel.js. this should not have happened");
1255+
// this usually happens hwen a git index is locked Eg. error.
1256+
// Error: Error: fatal: Unable to create 'E:/.../test-git/.git/index.lock': File exists.
1257+
//
1258+
// Another git process seems to be running in this repository, e.g.
1259+
// an editor opened by 'git commit'. Please make sure all processes
1260+
// are terminated then try again. If it still fails, a git process
1261+
// may have crashed in this repository earlier:
1262+
// remove the file manually to continue.
1263+
ErrorHandler.showError(err, Strings.ERROR_STAGE_FAILED, {
1264+
dontStripError: true,
1265+
errorMetric: "stageAll",
1266+
useNotification: true
1267+
});
12501268
});
12511269
}
12521270
return Git.resetIndex().then(function () {

src/nls/root/strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,7 @@ define({
15131513
"ERROR_CREATE_TAG": "Create tag failed",
15141514
"ERROR_CODE_INSPECTION_FAILED": "CodeInspection.inspectFile failed to execute for file",
15151515
"ERROR_CANT_GET_STAGED_DIFF": "Cant get diff for staged files",
1516+
"ERROR_STAGE_FAILED": "Failed to stage files in Git",
15161517
"ERROR_GIT_COMMIT_FAILED": "Git Commit failed",
15171518
"ERROR_GIT_BLAME_FAILED": "Git Blame failed",
15181519
"ERROR_GIT_DIFF_FAILED": "Git Diff failed",

src/styles/brackets.less

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,6 +3258,13 @@ label input {
32583258
transform: translateY(0);
32593259
}
32603260

3261+
.notification-popup-container.instantOpen {
3262+
opacity: 1;
3263+
transition: transform 100ms, opacity 100ms;
3264+
transition-delay: 100ms;
3265+
transform: translateY(0);
3266+
}
3267+
32613268
.notification-popup-container.animateClose {
32623269
transition: transform 500ms, opacity 500ms;
32633270
}

src/widgets/NotificationUI.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ define(function (require, exports, module) {
127127
endCB && endCB();
128128
}
129129
$NotificationPopup.removeClass("animateOpen");
130+
$NotificationPopup.removeClass("instantOpen");
130131
$NotificationPopup
131132
.addClass("animateClose")
132133
.one("transitionend", cleanup)
@@ -187,10 +188,11 @@ define(function (require, exports, module) {
187188
* The template can either be a string or a jQuery object representing a DOM node that is *not* in the current DOM.
188189
*
189190
* Creating a notification popup
191+
*
192+
* ```js
190193
* // note that you can even provide an HTML Element node with
191194
* // custom event handlers directly here instead of HTML text.
192195
* let notification1 = NotificationUI.createFromTemplate(
193-
* ```js
194196
* "<div>Click me to locate the file in file tree</div>", "showInfileTree",{
195197
* allowedPlacements: ['top', 'bottom'],
196198
* dismissOnClick: false,
@@ -345,12 +347,13 @@ define(function (require, exports, module) {
345347
* ```
346348
* @param {string} title The title for the notification.
347349
* @param {string|Element} template A string template or HTML Element to use as the dialog HTML.
348-
* @param {{dismissOnClick, autoCloseTimeS, toastStyle}} [options] optional, supported
350+
* @param {{dismissOnClick, autoCloseTimeS, toastStyle, instantOpen}} [options] optional, supported
349351
* * options are:
350352
* * `autoCloseTimeS` - Time in seconds after which the notification should be auto closed. Default is never.
351353
* * `dismissOnClick` - when clicked, the notification is closed. Default is true(dismiss).
352354
* * `toastStyle` - To style the toast notification for error, warning, info etc. Can be
353355
* one of `NotificationUI.NOTIFICATION_STYLES_CSS_CLASS.*` or your own css class name.
356+
* * `instantOpen` - To instantly open the popup without any open animation delays
354357
* @return {Notification} Object with a done handler that resolves when the notification closes.
355358
* @type {function}
356359
*/
@@ -378,7 +381,7 @@ define(function (require, exports, module) {
378381
// Animate in
379382
// Must wait a cycle for the "display: none" to drop out before CSS transitions will work
380383
setTimeout(function () {
381-
$NotificationPopup.addClass("animateOpen");
384+
$NotificationPopup.addClass( options.instantOpen ? "instantOpen" : "animateOpen");
382385
}, 0);
383386

384387
if(options.autoCloseTimeS){

0 commit comments

Comments
 (0)