Change string throws to Error throws (no stack trace with former)

This commit is contained in:
Adomas Venčkauskas 2018-07-18 16:44:03 +03:00
parent dfe412d448
commit b62b1968cf
15 changed files with 49 additions and 49 deletions

View file

@ -94,7 +94,7 @@ Zotero.Annotate = new function() {
}
return colorArray;
} catch(e) {
throw "Annotate: parseColor passed invalid color";
throw new Error("Annotate: parseColor passed invalid color");
}
}
@ -173,9 +173,9 @@ Zotero.Annotate = new function() {
} else if(offset < node.childNodes.length) {
node = node.childNodes[offset];
} else {
throw "Annotate: dereferenceNodeOffset called with invalid offset "+offset;
throw new Error("Annotate: dereferenceNodeOffset called with invalid offset "+offset);
}
if(!node) throw "Annotate: dereferenceNodeOffset resolved to invalid node";
if(!node) throw new Error("Annotate: dereferenceNodeOffset resolved to invalid node");
}
return node;
@ -308,7 +308,7 @@ Zotero.Annotate.Path = function(document, nsResolver, parent, textNode, offset)
* @param {Integer} offset The text offset, if the DOM node is a text node
*/
Zotero.Annotate.Path.prototype.fromNode = function(node, offset) {
if(!node) throw "Annotate: Path() called with invalid node";
if(!node) throw new Error("Annotate: Path() called with invalid node");
Zotero.debug("Annotate: Path() called with node "+node.tagName+" offset "+offset);
this.parent = "";
@ -345,7 +345,7 @@ Zotero.Annotate.Path.prototype.fromNode = function(node, offset) {
this.offset = 0;
}
}
if(!node) throw "Annotate: Path() handled Zotero <span> inappropriately";
if(!node) throw new Error("Annotate: Path() handled Zotero <span> inappropriately");
lastWasTextNode = lastWasTextNode || node.nodeType == TEXT_TYPE;
@ -387,7 +387,7 @@ Zotero.Annotate.Path.prototype.fromNode = function(node, offset) {
node = node.parentNode;
}
if(!node) throw "Annotate: Path() resolved text offset inappropriately";
if(!node) throw new Error("Annotate: Path() resolved text offset inappropriately");
while(node && node !== this._document) {
var number = 1;
@ -928,7 +928,7 @@ Zotero.Annotation.prototype.save = function() {
* Displays annotation
*/
Zotero.Annotation.prototype.display = function() {
if(!this.node) throw "Annotation not initialized!";
if(!this.node) throw new Error("Annotation not initialized!");
var x = 0, y = 0;
@ -946,7 +946,7 @@ Zotero.Annotation.prototype.display = function() {
* Displays annotation given absolute coordinates for its position
*/
Zotero.Annotation.prototype.displayWithAbsoluteCoordinates = function(absX, absY, select) {
if(!this.node) throw "Annotation not initialized!";
if(!this.node) throw new Error("Annotation not initialized!");
var startScroll = this.window.scrollMaxX;

View file

@ -113,7 +113,7 @@ Zotero.Cite = {
output.push("}");
return output.join("");
} else {
throw "Unimplemented bibliography format "+format;
throw new Error("Unimplemented bibliography format "+format);
}
} else {
if(format == "html") {
@ -176,9 +176,9 @@ Zotero.Cite = {
var secondFieldAlign = bib[0]["second-field-align"];
// Validate input
if(maxOffset == NaN) throw "Invalid maxoffset";
if(entrySpacing == NaN) throw "Invalid entryspacing";
if(lineSpacing == NaN) throw "Invalid linespacing";
if(maxOffset == NaN) throw new Error("Invalid maxoffset");
if(entrySpacing == NaN) throw new Error("Invalid entryspacing");
if(lineSpacing == NaN) throw new Error("Invalid linespacing");
var str;
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
@ -283,7 +283,7 @@ Zotero.Cite = {
return bib[0].bibstart+preamble+bib[1].join("\\\r\n")+"\\\r\n"+bib[0].bibend;
} else {
throw "Unimplemented bibliography format "+format;
throw new Error("Unimplemented bibliography format "+format);
}
},

View file

@ -61,7 +61,7 @@ Zotero.LocateManager = new function() {
*/
this.addEngine = function(engineURL, dataType, iconURL, confirm) {
if(dataType !== Components.interfaces.nsISearchEngine.TYPE_OPENSEARCH) {
throw "LocateManager supports only OpenSearch engines";
throw new Error("LocateManager supports only OpenSearch engines");
}
Zotero.HTTP.doGet(engineURL, function(xmlhttp) {
@ -121,7 +121,7 @@ Zotero.LocateManager = new function() {
*/
this.removeEngine = function(engine) {
var oldIndex = _locateEngines.indexOf(engine);
if(oldIndex === -1) throw "Engine is not currently listed";
if(oldIndex === -1) throw new Error("Engine is not currently listed");
_locateEngines.splice(oldIndex, 1);
engine._removeIcon();
_serializeLocateEngines();
@ -316,7 +316,7 @@ Zotero.LocateManager = new function() {
xns = {"s":doc.documentElement.namespaceURI,
"xmlns":"http://www.w3.org/2000/xmlns"};
if(OPENSEARCH_NAMESPACES.indexOf(ns) === -1) {
throw "Invalid namespace";
throw new Error("Invalid namespace");
}
// get simple attributes
@ -331,7 +331,7 @@ Zotero.LocateManager = new function() {
i = 0;
while(urlTags[i].hasAttribute("rel") && urlTags[i].getAttribute("rel") != "results") {
i++;
if(i == urlTags.length) throw "No Url tag found";
if(i == urlTags.length) throw new Error("No Url tag found");
}
// TODO: better error handling
@ -383,7 +383,7 @@ Zotero.LocateManager = new function() {
"getItemSubmission":function(item, responseType) {
if(responseType && responseType !== "text/html") {
throw "LocateManager supports only responseType text/html";
throw new Error("LocateManager supports only responseType text/html");
}
if (item.toJSON) {

View file

@ -52,7 +52,7 @@ Zotero.OpenURL = new function() {
req.send(null);
if(!req.responseXML) {
throw "Could not access resolver registry";
throw new Error("Could not access resolver registry");
}
var resolverArray = new Array();

View file

@ -379,7 +379,7 @@ Zotero.Proxy.prototype.validate = function() {
Zotero.Proxy.prototype.save = Zotero.Promise.coroutine(function* (transparent) {
// ensure this proxy is valid
var hasErrors = this.validate();
if(hasErrors) throw "Proxy: could not be saved because it is invalid: error "+hasErrors[0];
if(hasErrors) throw new Error("Proxy: could not be saved because it is invalid: error "+hasErrors[0]);
// we never save any changes to non-persisting proxies, so this works
var newProxy = !this.proxyID;
@ -420,7 +420,7 @@ Zotero.Proxy.prototype.save = Zotero.Promise.coroutine(function* (transparent) {
Zotero.Proxies.save(this);
} else {
Zotero.Proxies.refreshHostMap(this);
if(!transparent) throw "Proxy: cannot save transparent proxy without transparent param";
if(!transparent) throw new Error("Proxy: cannot save transparent proxy without transparent param");
}
});

View file

@ -253,7 +253,7 @@ We replace the bigger with the smaller.
if(typeof val == 'undefined')
return undefined;
else // @@ add converting of dates and numbers
throw "Can't make Term from " + val + " of type " + typeof val;
throw new Error("Can't make Term from " + val + " of type " + typeof val);
}
return val;
}

View file

@ -14,7 +14,7 @@ var $rdf = {
return;
}
}
throw "RDFArrayRemove: Array did not contain " + x;
throw new Error("RDFArrayRemove: Array did not contain " + x);
}
},
log: {

View file

@ -21,7 +21,7 @@ $rdf.N3Parser = function () {
var pyjslib_Dict = function (listOfPairs) {
if(listOfPairs.length > 0)
throw "missing.js: oops nnonempty dict not imp";
throw new Error("missing.js: oops nnonempty dict not imp");
return [];
}
@ -57,8 +57,8 @@ $rdf.N3Parser = function () {
var assertFudge = function (condition, desc) {
if(condition) return;
if(desc) throw "python Assertion failed: " + desc;
throw "(python) Assertion failed.";
if(desc) throw new Error("python Assertion failed: " + desc);
throw new Error("(python) Assertion failed.");
}

View file

@ -192,7 +192,7 @@ $rdf.Serializer = function () {
if (obj.termType == 'bnode' && (subjects[sz.toStr(obj)] &&
(force || (rootsHash[obj.toNT()] == undefined )))) {// and there are statements
if (doneBnodesNT[obj.toNT()]) { // Ah-ha! a loop
throw "Serializer: Should be no loops "+obj;
throw new Error("Serializer: Should be no loops "+obj);
}
doneBnodesNT[obj.toNT()] = true;
return dummyPropertyTree(obj, subjects, rootsHash);
@ -258,7 +258,7 @@ $rdf.Serializer = function () {
for (var i=0; i<sts.length; i++) {
// dump('\t'+sts[i]+'\n');
}
throw "Isolated node should be a subject" +found;
throw new Error("Isolated node should be a subject" +found);
}
dummySubjectTree(root, subjects, rootsHash); // trace out the ring
}
@ -456,7 +456,7 @@ $rdf.Serializer = function () {
return res;
default:
throw "Internal: termToN3 cannot handle " + expr + " of termType+" + expr.termType
throw new Error("Internal: termToN3 cannot handle " + expr + " of termType+" + expr.termType);
return '' + expr;
}
}
@ -767,7 +767,7 @@ $rdf.Serializer = function () {
'</' + t + '>']);
break;
default:
throw "Can't serialize object of type " + st.object.termType + " into XML";
throw new Error("Can't serialize object of type " + st.object.termType + " into XML");
} // switch
}
}
@ -830,7 +830,7 @@ $rdf.Serializer = function () {
'</' + qname(st.predicate) + '>']);
break;
default:
throw "Can't serialize object of type " + st.object.termType + " into XML";
throw new Error("Can't serialize object of type " + st.object.termType + " into XML");
} // switch
}

View file

@ -215,7 +215,7 @@ $rdf.Formula.prototype.add = function (subj, pred, obj, why) {
// Convenience methods on a formula allow the creation of new RDF terms:
$rdf.Formula.prototype.sym = function (uri, name) {
if(name != null) {
throw "This feature (kb.sym with 2 args) is removed. Do not assume prefix mappings."
throw new Error("This feature (kb.sym with 2 args) is removed. Do not assume prefix mappings.");
if(!$rdf.ns[uri]) throw 'The prefix "' + uri + '" is not set in the API';
uri = $rdf.ns[uri] + name
}
@ -316,7 +316,7 @@ $rdf.Formula.prototype.fromNT = function (str) {
if(k < len - 1) {
if(str[k + 1] == '@') lang = str.slice(k + 2, len);
else if(str.slice(k + 1, k + 3) == '^^') dt = $rdf.fromNT(str.slice(k + 3, len));
else throw "Can't convert string from NT: " + str
else throw new Error("Can't convert string from NT: " + str);
}
var str = (str.slice(1, k));
str = str.replace(/\\"/g, '"'); // unescape quotes '
@ -334,7 +334,7 @@ $rdf.Formula.prototype.fromNT = function (str) {
var x = new $rdf.Variable(str.slice(1));
return x;
}
throw "Can't convert from NT: " + str;
throw new Error("Can't convert from NT: " + str);
}
$rdf.fromNT = $rdf.Formula.prototype.fromNT; // Not for inexpert user

View file

@ -680,7 +680,7 @@ Zotero.Style = function (style, path) {
'/csl:style/csl:info[1]/csl:link[@rel="source" or @rel="independent-parent"][1]/@href',
Zotero.Styles.ns);
if(this.source === this.styleID) {
throw "Style with ID "+this.styleID+" references itself as source";
throw new Error("Style with ID "+this.styleID+" references itself as source");
}
}

View file

@ -2746,7 +2746,7 @@ Zotero.Translate.IO = {
}
if(nodes.getElementsByTagName("parsererror").length) {
throw "DOMParser error: loading data into data store failed";
throw new Error("DOMParser error: loading data into data store failed");
}
if("normalize" in nodes) nodes.normalize();

View file

@ -129,7 +129,7 @@ Zotero.Translate.DOMWrapper = new function() {
// No double wrapping.
if (isWrapper(obj))
throw "Trying to double-wrap object!";
throw new Error("Trying to double-wrap object!");
let dummy;
if (typeof obj === "function")
@ -151,7 +151,7 @@ Zotero.Translate.DOMWrapper = new function() {
// If we have a wrappable type, make sure it's wrapped.
if (!isWrapper(x))
throw "Trying to unwrap a non-wrapped object!";
throw new Error("Trying to unwrap a non-wrapped object!");
var obj = x.SpecialPowers_wrappedObject;
// unwrapped.
@ -253,7 +253,7 @@ Zotero.Translate.DOMWrapper = new function() {
},
defineProperty(target, prop, descriptor) {
throw "Can't call defineProperty on SpecialPowers wrapped object";
throw new Error("Can't call defineProperty on SpecialPowers wrapped object");
},
getOwnPropertyDescriptor(target, prop) {
@ -316,7 +316,7 @@ Zotero.Translate.DOMWrapper = new function() {
},
preventExtensions(target) {
throw "Can't call preventExtensions on SpecialPowers wrapped object";
throw new Error("Can't call preventExtensions on SpecialPowers wrapped object");
}
};
@ -870,7 +870,7 @@ Zotero.Translate.IO.Read.prototype = {
"setCharacterSet":function(charset) {
if(typeof charset !== "string") {
throw "Translate: setCharacterSet: charset must be a string";
throw new Error("Translate: setCharacterSet: charset must be a string");
}
// seek back to the beginning
@ -966,7 +966,7 @@ Zotero.Translate.IO.Write.prototype = {
"setCharacterSet":function(charset) {
if(typeof charset !== "string") {
throw "Translate: setCharacterSet: charset must be a string";
throw new Error("Translate: setCharacterSet: charset must be a string");
}
if(!this.outputStream) {

View file

@ -270,7 +270,7 @@ Zotero.Translators = new function() {
return Zotero.Translators.load(infoRe.exec(source)[0], path, source);
})
.catch(function() {
throw "Invalid or missing translator metadata JSON object in " + OS.Path.basename(path);
throw new Error("Invalid or missing translator metadata JSON object in " + OS.Path.basename(path));
});
}

View file

@ -160,7 +160,7 @@ Zotero.Utilities = {
var initialRe = new RegExp('^-?[' + allCaps + ']$');
if(typeof(author) != "string") {
throw "cleanAuthor: author must be a string";
throw new Error("cleanAuthor: author must be a string");
}
author = author.replace(/^[\s\u00A0\.\,\/\[\]\:]+/, '')
@ -224,7 +224,7 @@ Zotero.Utilities = {
*/
"trim":function(/**String*/ s) {
if (typeof(s) != "string") {
throw "trim: argument must be a string";
throw new Error("trim: argument must be a string");
}
s = s.replace(/^\s+/, "");
@ -250,7 +250,7 @@ Zotero.Utilities = {
*/
"superCleanString":function(/**String*/ x) {
if(typeof(x) != "string") {
throw "superCleanString: argument must be a string";
throw new Error("superCleanString: argument must be a string");
}
var x = x.replace(/^[\x00-\x27\x29-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F\s]+/, "");
@ -295,7 +295,7 @@ Zotero.Utilities = {
*/
"cleanTags":function(/**String*/ x) {
if(typeof(x) != "string") {
throw "cleanTags: argument must be a string";
throw new Error("cleanTags: argument must be a string");
}
x = x.replace(/<br[^>]*>/gi, "\n");
@ -309,7 +309,7 @@ Zotero.Utilities = {
*/
"cleanDOI":function(/**String**/ x) {
if(typeof(x) != "string") {
throw "cleanDOI: argument must be a string";
throw new Error("cleanDOI: argument must be a string");
}
var doi = x.match(/10(?:\.[0-9]{4,})?\/[^\s]*[^\s\.,]/);
@ -1223,7 +1223,7 @@ Zotero.Utilities = {
*/
"quotemeta":function(literal) {
if(typeof literal !== "string") {
throw "Argument "+literal+" must be a string in Zotero.Utilities.quotemeta()";
throw new Error("Argument "+literal+" must be a string in Zotero.Utilities.quotemeta()");
}
const metaRegexp = /[-[\]{}()*+?.\\^$|,#\s]/g;
return literal.replace(metaRegexp, "\\$&");