[IMP] throw actual errors in formatting functions, in order for browser devtools...
authorXavier Morel <xmo@openerp.com>
Thu, 10 Nov 2011 15:23:13 +0000 (16:23 +0100)
committerXavier Morel <xmo@openerp.com>
Thu, 10 Nov 2011 15:23:13 +0000 (16:23 +0100)
throwing strings prevents browser devtools/consoles from using traceback information (because there isn't any on strings)

bzr revid: xmo@openerp.com-20111110152313-phgtr24gyu2ltjn7

addons/web/static/src/js/dates.js
addons/web/static/src/js/formats.js

index 036cf8c..7861dd2 100644 (file)
@@ -18,11 +18,11 @@ openerp.web.str_to_datetime = function(str) {
     var regex = /^(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d)(?:\.\d+)?$/;
     var res = regex.exec(str);
     if ( !res ) {
-        throw "'" + str + "' is not a valid datetime";
+        throw new Error("'" + str + "' is not a valid datetime");
     }
     var obj = Date.parse(res[1] + " GMT");
     if (! obj) {
-        throw "'" + str + "' is not a valid datetime";
+        throw new Error("'" + str + "' is not a valid datetime");
     }
     return obj;
 };
@@ -41,11 +41,11 @@ openerp.web.str_to_date = function(str) {
     var regex = /^\d\d\d\d-\d\d-\d\d$/;
     var res = regex.exec(str);
     if ( !res ) {
-        throw "'" + str + "' is not a valid date";
+        throw new Error("'" + str + "' is not a valid date");
     }
     var obj = Date.parse(str);
     if (! obj) {
-        throw "'" + str + "' is not a valid date";
+        throw new Error("'" + str + "' is not a valid date");
     }
     return obj;
 };
@@ -64,11 +64,11 @@ openerp.web.str_to_time = function(str) {
     var regex = /^(\d\d:\d\d:\d\d)(?:\.\d+)?$/;
     var res = regex.exec(str);
     if ( !res ) {
-        throw "'" + str + "' is not a valid time";
+        throw new Error("'" + str + "' is not a valid time");
     }
     var obj = Date.parse(res[1]);
     if (! obj) {
-        throw "'" + str + "' is not a valid time";
+        throw new Error("'" + str + "' is not a valid time");
     }
     return obj;
 };
index ae40981..d5fcdd3 100644 (file)
@@ -157,7 +157,7 @@ openerp.web.auto_str_to_date = function(value, type) {
     try {
         return openerp.web.str_to_time(value);
     } catch(e) {}
-    throw "'" + value + "' is not a valid date, datetime nor time"
+    throw new Error("'" + value + "' is not a valid date, datetime nor time");
 };
 
 openerp.web.auto_date_to_str = function(value, type) {
@@ -169,7 +169,7 @@ openerp.web.auto_date_to_str = function(value, type) {
         case 'time':
             return openerp.web.time_to_str(value);
         default:
-            throw type + " is not convertible to date, datetime nor time"
+            throw new Error(type + " is not convertible to date, datetime nor time");
     }
 };