Author: reebalazs
Date: Fri Dec 28 12:42:06 2007
New Revision: 50154
Added:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_errors.js
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/ (props changed)
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/errors.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/providerreg.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/resourcedata.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runner.html
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runtests.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runtests.sh
Log:
Change valueproviders to store a registry object intead of just the classname,
meanwhile neexed to fix the chaining of the error exceptions,
suffitient tests provided as well.
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/errors.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/errors.js
(original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/errors.js
Fri Dec 28 12:42:06 2007
@@ -77,6 +77,20 @@
// the original traceback will be lost.
e = new Error(e);
}
+ // If there is no info on the error object, we need to
+ // create an initial info for that error, to have the
+ // full chain of annotations available, including the ultimate
+ // message.
+;;; if (addMessage && ! e.info) {
+;;; // We are just starting with an error that has not
+;;; // been annotated yet.
+;;; // In this case we will give it an annotation
+;;; e.info = new ErrorAnnotation();
+;;; e.info.name = e.name;
+;;; e.info.message = e.message;
+;;; e.info.fullMessage = e.message;
+;;; e.info.kw = {};
+;;; }
;;; this.previous_info = e.info;
e.name = name;
e.info = this;
@@ -90,23 +104,35 @@
return e;
};
;;;
-;;; this._logRecursive = function() {
-;;; kukit.logError(this.message);
+;;; this._iterateInfo = function(yield) {
+;;; yield.call(this, this.message);
;;; if (this.previous_info) {
-;;; this.previous_info._logRecursive();
+;;; this.previous_info._iterateInfo(yield);
;;; }
;;; };
;;;
+;;; this.getInfoChain = function() {
+;;; result = [];
+;;; this._iterateInfo(function(msg) {
+;;; result.push(msg);
+;;; });
+;;; return result;
+;;; };
+;;;
;;; this.log = function() {
;;; // This is for debugging only, normal error handling
;;; // does not use it.
;;; kukit.logFatal('KSS error, stack information follows:');
+;;; this._iterateInfo(function(msg) {
+;;; kukit.logError(msg);
+;;; });
;;; this._logRecursive();
;;; };
};
-var setErrorInfo = function(e, name, message, kw) {
+// setErrorInfo needs to be global, for ecma testing
+var setErrorInfo = err.setErrorInfo = function(e, name, message, kw) {
return new ErrorAnnotation().constructError(e, name, message, kw);
};
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/providerreg.js
==============================================================================
---
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/providerreg.js
(original)
+++
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/providerreg.js
Fri Dec 28 12:42:06 2007
@@ -39,7 +39,7 @@
var iface = kukit.interfaces.global.get(this.name,
kukit.interfaces.PluginMethodDescriptor);
var descriptor = iface.getMethodDescriptor(name);
- descriptor.register(func);
+ descriptor.register({providerClass: func});
};
kukit.pprovidersGlobalRegistry = new
kukit.pr.ValueProviderRegistry('valueproviders');
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/resourcedata.js
==============================================================================
---
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/resourcedata.js
(original)
+++
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/resourcedata.js
Fri Dec 28 12:42:06 2007
@@ -225,7 +225,7 @@
kukit.rd.KssTextValue.prototype.check = function(iface) {
// use the IdentityPP provider.
- this.pprovider = new (iface[''])();
+ this.pprovider = new (iface['']).providerClass();
};
kukit.rd.KssTextValue.prototype.evaluate =
@@ -252,13 +252,13 @@
// Check syntax
var f = iface[this.methodName];
// Check if the method name really existed.
- if (! f) {
+ if (! f || ! f.providerClass) {
;;; kukit.E = 'Undefined value provider [';
;;; kukit.E += this.methodName + '].';
throw kukit.err.pluginRegistryError(null, kukit.E);
}
// Create the provider checker and evaluator object
- this.pprovider = new f();
+ this.pprovider = new f.providerClass();
// Check the providers, this will give errors
// in case something is wrong with the parameters.
// Checking is also needed in production mode.
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runner.html
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runner.html
(original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runner.html
Fri Dec 28 12:42:06 2007
@@ -89,6 +89,7 @@
<script type="text/javascript" src="test_tokenizer.js"> </script>
<script type="text/javascript" src="test_kssparser.js"> </script>
<script type="text/javascript" src="test_interfaces.js"> </script>
+ <script type="text/javascript" src="test_errors.js"> </script>
</head>
<body>
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runtests.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runtests.js
(original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runtests.js
Fri Dec 28 12:42:06 2007
@@ -26,6 +26,7 @@
testsuite.registerTest(kukit.InterfacesTestCase);
testsuite.registerTest(kukit.ServiceInterfacesTestCase);
testsuite.registerTest(kukit.PluginInterfacesTestCase);
+ testsuite.registerTest(kukit.ErrorsTestCase);
testsuite.runSuite();
};
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runtests.sh
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runtests.sh
(original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runtests.sh
Fri Dec 28 12:42:06 2007
@@ -28,4 +28,5 @@
-f test_tokenizer.js \
-f test_kssparser.js \
-f test_interfaces.js \
+ -f test_errors.js \
runtests.js
Added:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_errors.js
==============================================================================
--- (empty file)
+++
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_errors.js
Fri Dec 28 12:42:06 2007
@@ -0,0 +1,151 @@
+/*
+* Copyright (c) 2007
+* Authors: KSS Project Contributors (see doc/CREDITS.txt)
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as published
+* by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+* 02111-1307, USA.
+*/
+
+if (typeof(kukit) == "undefined") {
+ var kukit = {};
+}
+
+kukit.ErrorsTestCase = function() {
+ this.name = 'kukit.ErrorsTestCase';
+
+ this.setUp = function() {
+ };
+
+ this.testCreateGenuineError = function() {
+ // Create a genuine error message.
+ // An error message of a given type can be created on the fly.
+ var E = kukit.err.setErrorInfo(null, 'MyError', 'Something went
wrong', {a:1, b:2});
+ // Check that error has the message
+ this.assertEquals(E.message, 'MyError: Something went wrong');
+ this.assertNotEquals(typeof(E.info), 'undefined');
+ this.assertListEquals(E.info.getInfoChain(), [
+ 'Something went wrong']);
+ this.assertDictEquals(E.info.kw, {a:1, b:2});
+ };
+
+ this.testCreateErrorFromTxt = function() {
+ // Create an annotated error from text.
+ // XXX this works but gives warning: this way we cannot preserve the
traceback.
+ var orig_txt = "Original error";
+ var E = kukit.err.setErrorInfo(orig_txt, 'MyError', 'Something went
wrong', {a:1, b:2});
+ // Check that error has the message
+ this.assertEquals(E.message, 'MyError: Something went wrong [Original
error]');
+ this.assertNotEquals(typeof(E.info), 'undefined');
+ this.assertListEquals(E.info.getInfoChain(), [
+ 'Something went wrong',
+ 'Original error']);
+ this.assertDictEquals(E.info.kw, {a:1, b:2});
+ };
+
+ this.testCreateErrorFromRawError = function() {
+ // Create an annotated error from a raw, unannorated error.
+ var orig_err = new Error("Original error");
+ var E = kukit.err.setErrorInfo(orig_err, 'MyError', 'Something went
wrong', {a:1, b:2});
+ // Check that error has the message
+ this.assertEquals(E.message, 'MyError: Something went wrong [Original
error]');
+ this.assertNotEquals(typeof(E.info), 'undefined');
+ this.assertListEquals(E.info.getInfoChain(), [
+ 'Something went wrong',
+ 'Original error']);
+ this.assertDictEquals(E.info.kw, {a:1, b:2});
+ };
+
+ this.testCreateErrorFromAnnotatedError = function() {
+ // Create an error from an annotated error message.
+ // this message is a genuine error created by us
+ // create chain of errors
+ var orig_err = kukit.err.setErrorInfo(null, 'MyError', 'Something went
wrong', {a:1, b:2});
+ var E = kukit.err.setErrorInfo(orig_err, 'YourError', 'Wrong here
too', {a:2, b:3});
+ // Check that error has the message
+ this.assertEquals(E.message, 'YourError: Wrong here too [MyError:
Something went wrong]');
+ this.assertNotEquals(typeof(E.info), 'undefined');
+ this.assertListEquals(E.info.getInfoChain(), [
+ 'Wrong here too',
+ 'Something went wrong']);
+ this.assertDictEquals(E.info.kw, {a:2, b:3});
+ };
+
+ this.testCreateErrorFromAnnotatedError2 = function() {
+ // Create an error from an annotated error message.
+ // this message is a string error
+ // create chain of errors
+ var orig_txt = "Original error";
+ var err1 = kukit.err.setErrorInfo(orig_txt, 'MyError', 'Something went
wrong', {a:1, b:2});
+ var E = kukit.err.setErrorInfo(err1, 'YourError', 'Wrong here too',
{a:2, b:3});
+ // Check that error has the message
+ this.assertEquals(E.message, 'YourError: Wrong here too [MyError:
Something went wrong [Original error]]');
+ this.assertNotEquals(typeof(E.info), 'undefined');
+ this.assertListEquals(E.info.getInfoChain(), [
+ 'Wrong here too',
+ 'Something went wrong',
+ 'Original error']);
+ this.assertDictEquals(E.info.kw, {a:2, b:3});
+ };
+
+ this.testCreateErrorFromAnnotatedError3 = function() {
+ // Create an error from an annotated error message.
+ // This message is an unannotated error object
+ // create chain of errors
+ var orig_err = new Error("Original error");
+ var err1 = kukit.err.setErrorInfo(orig_err, 'MyError', 'Something went
wrong', {a:1, b:2});
+ var E = kukit.err.setErrorInfo(err1, 'YourError', 'Wrong here too',
{a:2, b:3});
+ // Check that error has the message
+ this.assertEquals(E.message, 'YourError: Wrong here too [MyError:
Something went wrong [Original error]]');
+ this.assertNotEquals(typeof(E.info), 'undefined');
+ this.assertListEquals(E.info.getInfoChain(), [
+ 'Wrong here too',
+ 'Something went wrong',
+ 'Original error']);
+ this.assertDictEquals(E.info.kw, {a:2, b:3});
+ };
+
+ this.testCreateErrorManyLevels = function() {
+ // Many levels together
+ // create chain of errors
+ var orig_err = new Error("Original error");
+ var err1 = kukit.err.setErrorInfo(orig_err, 'Error1', 'Wrong 1', {a:1,
b:2});
+ var err2 = kukit.err.setErrorInfo(err1, 'Error2', 'Wrong 2', {a:2,
b:3});
+ var err3 = kukit.err.setErrorInfo(err2, 'Error3', 'Wrong 3', {a:3,
b:4});
+ var err4 = kukit.err.setErrorInfo(err3, 'Error4', 'Wrong 4', {a:4,
b:5});
+ var E = kukit.err.setErrorInfo(err3, 'Error5', 'Wrong 5', {a:5, b:6});
+ // Check that error has the message
+ this.assertEquals(E.message,
+ 'Error5: Wrong 5 [Error4: Wrong 4 [Error3: Wrong 3 [Error2: Wrong 2
[Error1: Wrong 1 [Original error]]]]]');
+ this.assertNotEquals(typeof(E.info), 'undefined');
+ this.assertListEquals(E.info.getInfoChain(), [
+ 'Wrong 5',
+ 'Wrong 4',
+ 'Wrong 3',
+ 'Wrong 2',
+ 'Wrong 1',
+ 'Original error']);
+ this.assertDictEquals(E.info.kw, {a:5, b:6});
+ };
+
+
+
+
+
+};
+
+kukit.ErrorsTestCase.prototype = new kukit.UtilsTestCaseBase;
+
+if (typeof(testcase_registry) != 'undefined') {
+ testcase_registry.registerTestCase(kukit.ErrorsTestCase,
'kukit.ErrorsTestCase');
+}
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins