-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix #3412: Cryptic error message when addMenuItem() is passed bad args #3611
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,23 +91,32 @@ define(function (require, exports, module) { | |
|
||
|
||
/** | ||
* Insertion position constants | ||
* Used by addMenu(), addMenuItem(), and addSubMenu() to | ||
* specify the relative position of a newly created menu object | ||
* @enum {string} | ||
*/ | ||
var BEFORE = "before"; | ||
var AFTER = "after"; | ||
var FIRST = "first"; | ||
var LAST = "last"; | ||
var FIRST_IN_SECTION = "firstInSection"; | ||
var LAST_IN_SECTION = "lastInSection"; | ||
|
||
/** | ||
* Other constants | ||
*/ | ||
var DIVIDER = "---"; | ||
* Insertion position constants | ||
* Used by addMenu(), addMenuItem(), and addSubMenu() to | ||
* specify the relative position of a newly created menu object | ||
* @enum {string} | ||
*/ | ||
var BEFORE = "before"; | ||
var AFTER = "after"; | ||
var FIRST = "first"; | ||
var LAST = "last"; | ||
var FIRST_IN_SECTION = "firstInSection"; | ||
var LAST_IN_SECTION = "lastInSection"; | ||
|
||
/** | ||
* Other constants | ||
*/ | ||
var DIVIDER = "---"; | ||
|
||
/** | ||
* Error Codes from Brackets Shell | ||
* @enum {number} | ||
*/ | ||
var NO_ERROR = 0; | ||
var ERR_UNKNOWN = 1; | ||
var ERR_INVALID_PARAMS = 2; | ||
var ERR_NOT_FOUND = 3; | ||
|
||
/** | ||
* Maps menuID's to Menu objects | ||
* @type {Object.<string, Menu>} | ||
|
@@ -462,7 +471,8 @@ define(function (require, exports, module) { | |
* @return {MenuItem} the newly created MenuItem | ||
*/ | ||
Menu.prototype.addMenuItem = function (command, keyBindings, position, relativeID) { | ||
var id, | ||
var menuID = this.id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really. I added it to be able to access the menu ID in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, that makes sense. Would it make sense to change all other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the other reference don't need to be changed since those can use the this object to access the menu id, but they could be changed if required. |
||
id, | ||
$menuItem, | ||
$link, | ||
menuItem, | ||
|
@@ -547,8 +557,13 @@ define(function (require, exports, module) { | |
} | ||
|
||
brackets.app.addMenuItem(this.id, name, commandID, bindingStr, displayStr, position, relativeID, function (err) { | ||
if (err) { | ||
console.error("addMenuItem() -- error: " + err + " when adding command: " + commandID); | ||
switch (err) { | ||
case ERR_INVALID_PARAMS: | ||
console.error("addMenuItem(): Invalid Parameters when adding the command " + commandID); | ||
break; | ||
case ERR_NOT_FOUND: | ||
console.error("_getRelativeMenuItem(): MenuItem with Command id " + relativeID + " not found in the Menu " + menuID); | ||
break; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also need a |
||
}); | ||
menuItem.isNative = true; | ||
|
@@ -800,15 +815,24 @@ define(function (require, exports, module) { | |
|
||
if (!_isHTMLMenu(id)) { | ||
brackets.app.addMenu(name, id, position, relativeID, function (err) { | ||
if (err) { | ||
console.error("addMenu() -- error: " + err + " when adding menu with ID: " + id); | ||
} else { | ||
switch (err) { | ||
case ERR_UNKNOWN: | ||
console.error("addMenu(): Unknown Error when adding the menu " + id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found this error in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be a catchall value passed from brackets-shell, so this is ok. This
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also need a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one does have a NO_ERROR case that does what the else branch did previously. |
||
break; | ||
case ERR_INVALID_PARAMS: | ||
console.error("addMenu(): Invalid Parameters when adding the menu " + id); | ||
break; | ||
case ERR_NOT_FOUND: | ||
console.error("addMenu(): Menu with command " + relativeID + " could not be found when adding the menu " + id); | ||
break; | ||
case NO_ERROR: | ||
// Make sure name is up to date | ||
brackets.app.setMenuTitle(id, name, function (err) { | ||
if (err) { | ||
console.error("setMenuTitle() -- error: " + err); | ||
} | ||
}); | ||
break; | ||
} | ||
}); | ||
return menu; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're cleaning up this code, could you make this a single
var
statement with comma-separated declarations?Same for Error Codes below.