From 78dec879cfa55787813bbd7bb222bddbf7d36aee Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 10 Nov 2011 16:23:13 +0100 Subject: [PATCH] [IMP] throw actual errors in formatting functions, in order for browser devtools to be useful 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 | 12 ++++++------ addons/web/static/src/js/formats.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/addons/web/static/src/js/dates.js b/addons/web/static/src/js/dates.js index 036cf8cd90b..7861dd21b79 100644 --- a/addons/web/static/src/js/dates.js +++ b/addons/web/static/src/js/dates.js @@ -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; }; diff --git a/addons/web/static/src/js/formats.js b/addons/web/static/src/js/formats.js index ae40981e1a7..d5fcdd35b62 100644 --- a/addons/web/static/src/js/formats.js +++ b/addons/web/static/src/js/formats.js @@ -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"); } };