[KSS-checkins] r49377 - kukit/kukit.js/trunk/kukit
reebalazs at codespeak.net
reebalazs at codespeak.net
Wed Dec 5 13:33:55 CET 2007
Author: reebalazs
Date: Wed Dec 5 13:33:55 2007
New Revision: 49377
Modified:
kukit/kukit.js/trunk/kukit/commandprocessor.js
kukit/kukit.js/trunk/kukit/errors.js
kukit/kukit.js/trunk/kukit/kukit.js
kukit/kukit.js/trunk/kukit/serveraction.js
Log:
Fix error handling.
Due to excess commenting, the following problems persisted:
- error fallback actions were not executed in production mode
- explicit error reason (server reason = ) was never displayed
(neither in producttion and development mode)
- If there is a problem with the kukit response, there is no
error signalled in production mode.
I still could not solve this last one.
At the moment error demo works correctly.
Modified: kukit/kukit.js/trunk/kukit/commandprocessor.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/commandprocessor.js (original)
+++ kukit/kukit.js/trunk/kukit/commandprocessor.js Wed Dec 5 13:33:55 2007
@@ -41,8 +41,9 @@
// we make sure we execute none of them.
var lastcommand = this.commands[this.commands.length-1];
if (lastcommand.name == 'error') {
-;;; throw kukit.err.explicitError(lastcommand);
- throw new Error(kukit.E);
+ // We have to throw an explicitError always, since we want
+ // error fallbacks work both in production and development mode.
+ throw kukit.err.explicitError(lastcommand);
}
}
};
Modified: kukit/kukit.js/trunk/kukit/errors.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/errors.js (original)
+++ kukit/kukit.js/trunk/kukit/errors.js Wed Dec 5 13:33:55 2007
@@ -55,67 +55,84 @@
*/
-;;; var ErrorAnnotation = function() {
-;;;
-;;; this.constructError = function(e, name, message, kw) {
-;;; if (typeof(kw) == "undefined") {
-;;; kw = {};
-;;; }
-;;; this.kw = kw;
-;;; this.message = name + ': ' + message;
-;;; var addMessage = true;
-;;; if (!e) {
-;;; e = new Error(message);
-;;; addMessage = false;
-;;; } else if (typeof(e) == "string") {
-;;; kukit.E = 'Do not raise string exceptions, as we cannot ';
-;;; kukit.E += 'annotate them properly. Use: throw new Error(msg);';
-;;; e = new Error(e);
-;;; }
-;;; this.previous_info = e.info;
-;;; e.name = name;
-;;; e.info = this;
-;;; if (addMessage) {
-;;; var fullMessage = message + ' [' + e.message + ']';
-;;; // for FF, and Safari:
-;;; e.message = fullMessage;
-;;; // for IE, message is ignored, description is used.
-;;; e.description = fullMessage;
+var ErrorAnnotation = function() {
+
+ this.constructError = function(e, name, message, kw) {
+;;; if (typeof(kw) == "undefined") {
+;;; kw = {};
+;;; }
+ this.kw = kw;
+;;; this.message = name + ': ' + message;
+;;; var addMessage = true;
+ if (!e) {
+;;; e = new Error(message);
+;;; addMessage = false;
+;;; } else if (typeof(e) == "string") {
+;;; kukit.E = 'Do not raise string exceptions, as we cannot ';
+;;; kukit.E += 'annotate them properly. Use: throw new Error(msg);';
+ e = new Error(kukit.E);
+ }
+;;; this.previous_info = e.info;
+ e.name = name;
+ e.info = this;
+;;; if (addMessage) {
+;;; var fullMessage = message + ' [' + e.message + ']';
+;;; // for FF, and Safari:
+;;; e.message = fullMessage;
+;;; // for IE, message is ignored, description is used.
+;;; e.description = fullMessage;
;;; }
-;;; return e;
-;;; };
+ return e;
+ };
;;;
-;;; this._logRecursive = function() {
-;;; kukit.logError(this.message);
-;;; if (this.previous_info) {
-;;; this.previous_info._logRecursive();
-;;; }
-;;; };
+;;; this._logRecursive = function() {
+;;; kukit.logError(this.message);
+;;; if (this.previous_info) {
+;;; this.previous_info._logRecursive();
+;;; }
+;;; };
;;;
-;;; this.log = function() {
-;;; // This is for debugging only, normal error handling
-;;; // does not use it.
-;;; kukit.logFatal('KSS error, stack information follows:');
-;;; this._logRecursive();
-;;; };
+;;; this.log = function() {
+;;; // This is for debugging only, normal error handling
+;;; // does not use it.
+;;; kukit.logFatal('KSS error, stack information follows:');
+;;; this._logRecursive();
;;; };
-;;; var setErrorInfo = function(e, name, message, kw) {
-;;; return new ErrorAnnotation().constructError(e, name, message, kw);
-;;; };
+};
+
+var setErrorInfo = function(e, name, message, kw) {
+ return new ErrorAnnotation().constructError(e, name, message, kw);
+};
/* Protects a function */
-;;; err.explicitError = function(errorcommand){
-;;; var kw = {'errorcommand':errorcommand};
-;;; var message = 'Explicit error';
-;;; return setErrorInfo(null, 'ExplicitError', message, kw);
-;;; };
-
-;;; err.responseParsingError = function(message){
-;;; return setErrorInfo(null, 'ResponseParsingError', message);
-;;; };
+/*
+ * Explicit error represents that the server side action failed and
+ * we need to handle this with an explicit error action defined from
+ * kss.
+ * There are three main cases when this can happen:
+ *
+ * 1. In case the server explicitely sent us an error (hence the
+ * name of this class) the parameter will contain the kss
+ * command from the payload.
+ *
+ * 2. If a payload response parsing error lead us here, then it
+ * will contain a string of the error message.
+ *
+ * 3. If a timeout of the response happened, the parameter will
+ * contain the text "timeout".
+ */
+err.explicitError = function(errorcommand){
+ var kw = {'errorcommand': errorcommand};
+;;; kukit.E = 'Explicit error';
+ return setErrorInfo(null, 'ExplicitError', kukit.E, kw);
+};
+
+err.responseParsingError = function(message){
+ return setErrorInfo(null, 'ResponseParsingError', message);
+};
;;; err.ruleMergeError = function(message){
;;; return setErrorInfo(null, 'RuleMergeError', message);
Modified: kukit/kukit.js/trunk/kukit/kukit.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/kukit.js (original)
+++ kukit/kukit.js/trunk/kukit/kukit.js Wed Dec 5 13:33:55 2007
@@ -92,7 +92,8 @@
if((nodes[i].type == 'text/css') || (nodes[i].type == 'text/kss')) {
res_type = 'kss';
;;; } else {
-;;; throw kukit.err.explicitError("rel type is not text/css or text/kss");
+;;; // Just show this, and go on with the processing.
+;;; kukit.logError("rel type is not text/css or text/kss");
}
var newRuleLink = new kukit.RuleSheetLink(nodes[i].href, res_type);
results[results.length] = newRuleLink;
Modified: kukit/kukit.js/trunk/kukit/serveraction.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/serveraction.js (original)
+++ kukit/kukit.js/trunk/kukit/serveraction.js Wed Dec 5 13:33:55 2007
@@ -111,20 +111,24 @@
if (success) {
// catch the errors otherwise won't get logged.
// In FF they seem to get swallowed silently.
-;;; try {
+ // We need these both in production and development mode,
+ // since the erorr fallbacks are activated from processError.
+ try {
// process the results
this.processResult(domDoc);
-;;; } catch(e) {
+ } catch(e) {
;;; if (e.name == 'RuleMergeError' || e.name == 'EventBindError') {
;;; throw kukit.err.eventSetupError(e);
-;;; } else if (e.name == 'ResponseParsingError') {
-;;; this.processError('Response parsing error: ' + e);
-;;; } else if (e.name == 'ExplicitError') {
-;;; this.processError(e.errorcommand);
-;;; } else {
-;;; throw e;
-;;; }
-;;; }
+;;; }
+ if (e.name == 'ResponseParsingError') {
+;;; kukit.E = 'Response parsing error: ' + e;
+ this.processError(kukit.E);
+ } else if (e.name == 'ExplicitError') {
+ this.processError(e.info.kw.errorcommand);
+ } else {
+ throw e;
+ }
+ }
}
}
};
@@ -151,9 +155,8 @@
try {
dom = (new DOMParser()).parseFromString(payload, "text/xml");
} catch(e) {
-;;; var msg = 'Error parsing X-KSSCOMMANDS header.';
-;;; throw kukit.err.responseParsingError(msg);
- throw new Error(kukit.E);
+;;; kukit.E = 'Error parsing X-KSSCOMMANDS header.';
+ throw kukit.err.responseParsingError(kukit.E);
}
commandstags = kukit.dom.getNsTags(dom, 'commands');
if (commandstags.length != 1) {
@@ -166,21 +169,19 @@
// and log it as reported from the dom
// Opera <= 8.5 does not have the parseError attribute,
// so check for it first
- dom = domDoc.responseXML;
-;;; var msg = 'Unknown server error (invalid KSS response, no error';
-;;; msg += ' info received)';
+;;; dom = domDoc.responseXML;
+;;; kukit.E = 'Unknown server error (invalid KSS response, no error';
+;;; kukit.E += ' info received)';
;;; if (dom && dom.parseError && (dom.parseError != 0)) {
-;;; msg += ' : ' + Sarissa.getParseErrorText(dom);
+;;; kukit.E += ' : ' + Sarissa.getParseErrorText(dom);
;;; }
-;;; throw kukit.err.responseParsingError(msg);
- throw new Error(kukit.E);
+ throw kukit.err.responseParsingError(kukit.E);
}
}
if (dom == null) {
// this should not happen
-;;; var msg = 'Neither xml nor html payload.';
-;;; throw kukit.err.responseParsingError(msg);
- throw new Error(kukit.E);
+;;; kukit.E = 'Neither xml nor html payload.';
+ throw kukit.err.responseParsingError(msg);
}
// find the commands (atm we don't limit ourselves inside the commandstag)
var commands = kukit.dom.getNsTags(dom, 'command');
@@ -207,6 +208,9 @@
;;; reason = ', client_reason="' + errorcommand + '" ';
;;; } else if (typeof(errorcommand) != 'undefined') {
;;; // a real error command, sent by the server
+;;; // as kukit payload.
+;;; // this way the server sends whatever message he wants as a parameter
+;;; // to the error command.
;;; reason = ', server_reason="' + errorcommand.parms.message + '" ';
;;; }
if (error_action) {
@@ -221,6 +225,14 @@
;;; kukit.E = 'Request failed at url ' + this.oper.queueItem.url;
;;; kukit.E += ', rid=' + this.oper.queueItem.rid + reason;
;;; kukit.logError(kukit.E);
+;;; return;
+ // in case of no logging, we would like to throw an error.
+ // This means user will see something went wrong.
+ // XXX But: throwing an error on Firefox
+ // _seems to be ineffective__
+ // and throwing the error from IE
+ // _throws an ugly window, "Uncaught exception"
+ // TODO figure out something?
}
-};
+;
More information about the Kukit-checkins
mailing list