[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
This commit is contained in:
Xavier Morel 2011-11-10 16:23:13 +01:00
parent 126a9129a6
commit 78dec879cf
2 changed files with 8 additions and 8 deletions

View 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;
};

View 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");
}
};