[KSS-checkins] r35983 - kukit/kukit.js/trunk/kukit

reebalazs at codespeak.net reebalazs at codespeak.net
Tue Dec 26 12:16:46 CET 2006


Author: reebalazs
Date: Tue Dec 26 12:16:44 2006
New Revision: 35983

Modified:
   kukit/kukit.js/trunk/kukit/kukit.js
   kukit/kukit.js/trunk/kukit/plugin.js
Log:
Implement an error command that can be used to signal an error condition with a reason displayed in the kss log.

Modified: kukit/kukit.js/trunk/kukit/kukit.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/kukit.js	(original)
+++ kukit/kukit.js/trunk/kukit/kukit.js	Tue Dec 26 12:16:44 2006
@@ -221,6 +221,16 @@
 
 /* Server notification */
 
+// this should be thrown with the error command as parameter
+kukit.ExplicitError = kukit.ut.exceptionFactory('ExplicitError');
+kukit.ExplicitError.prototype.__superinit__ = kukit.ExplicitError.prototype.__init__;
+kukit.ExplicitError.prototype.__init__ = function(name, errorcommand) {
+    var message = 'Explicit error, reason=' + errorcommand.parms.message;
+    var kw = this.__superinit__(name, message);
+    kw.errorcommand = errorcommand;
+    return kw
+};
+
 // Backparms can be used on command execution.
 kukit.notifyServer = function(url, params, oper) {
     var sendHook = function(queueItem) {
@@ -278,6 +288,8 @@
                     kukit.logFatal(msg);
                     // just throw it too...
                     throw msg;
+                } else if (e.name == 'ExplicitError') {
+                    kukit.processError(oper, e.errorcommand);
                 } else {
                     kukit.logError('Unhandled error during command execution: ' + e);
                     // also IE acts foul on thrown errors
@@ -312,8 +324,7 @@
         //   1. No response from server, and browser notifies us with an empty response
         //   2. There was an error on the server, and we got an error message as response
         // Call the error handler.
-        kukit.processError(oper);
-        return;
+        throw new kukit.ExplicitError();
     }
     // Opera <= 8.5 does not have the parseError attribute, so check for it first
     if (domXml.parseError && (domXml.parseError != 0)) {
@@ -330,18 +341,22 @@
     command_processor.executeCommands(oper);
 };
 
-kukit.processError = function(oper) {
+kukit.processError = function(oper, errorcommand) {
     var error_action = null;
     if (oper.eventrule) {
         var error_action = oper.eventrule.actions.getErrorActionFor(oper.action);
         }
+    var reason = '';
+    if (typeof(errorcommand) != 'undefined') {
+        reason = ', reason="' + errorcommand.parms.message + '" '
+    }
     if (error_action) {
-        kukit.logWarning('Request failed at url ' + oper.queueItem.url + ', rid=' + oper.queueItem.rid + ', will be handled by action "' + error_action.name + '"');
+        kukit.logWarning('Request failed at url ' + oper.queueItem.url + ', rid=' + oper.queueItem.rid + reason + ', will be handled by action "' + error_action.name + '"');
         // Individual error handler was defined. Execute it!
         error_action.execute(oper);
     } else {
         // Unhandled: just log it...
-        kukit.logError('Request failed at url ' + oper.queueItem.url + ', rid=' + oper.queueItem.rid);
+        kukit.logError('Request failed at url ' + oper.queueItem.url + ', rid=' + oper.queueItem.rid) + reason;
     }
 };
 
@@ -363,6 +378,14 @@
     for (var y=0;y < commands.length;y++) {
         var command = commands[y];
         this.parseCommand(command, transport);
+        // If we receive an error command, we handle that separately.
+        // We abort immediately and let the processError handler do its job.
+        // This means that although no other commands should be in commands,
+        // we make sure we execute none of them.
+        var lastcommand = this.commands[this.commands.length-1];
+        if (lastcommand.name == 'error') {
+            throw new kukit.ExplicitError(lastcommand);
+        }
     }
 };
 

Modified: kukit/kukit.js/trunk/kukit/plugin.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/plugin.js	(original)
+++ kukit/kukit.js/trunk/kukit/plugin.js	Tue Dec 26 12:16:44 2006
@@ -312,6 +312,12 @@
 * They also get registered as commands
 */
 
+kukit.ar.actionRegistry.register("error", function (oper) {
+    throw 'The builtin error action should never execute.';
+    }
+);
+kukit.cr.commandRegistry.registerFromAction('error', kukit.cr.makeGlobalCommand);
+
 kukit.ar.actionRegistry.register("logDebug", function (oper) {
     oper.completeParms([], {'message': 'Logging from Event'}, 'logDebug action');
     var node = oper.node;


More information about the Kukit-checkins mailing list