Repository: canjs/can-zone (js)

Issue:
can-zone adds cycle to errors 
```js
error = {
    message: ...
    errors: [ error ]
    ...
}
```

This cycle will cause problems downstream if any tool tries to serialize the error,  see https://github.com/stealjs/steal/issues/1509 for more details.

Pull request description:
Prevent can-zone from creating circular errors
Closes #193

Patch:
diff --git a/appveyor.yml b/appveyor.yml
index 31b7ae6..4aff770 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -2,7 +2,8 @@
 environment:
   matrix:
   # node.js
-  - nodejs_version: "7"
+  - nodejs_version: "8"
+  - nodejs_version: "10"
 
 # Install scripts. (runs after repo cloning)
 install:
diff --git a/lib/zone.js b/lib/zone.js
index ccf2cd7..54d1857 100644
--- a/lib/zone.js
+++ b/lib/zone.js
@@ -269,7 +269,7 @@ Zone.prototype.end = function(){
 	var dfd = this.deferred;
 	if(this.errors.length) {
 		var error = this.errors[0];
-		error.errors = this.errors;
+		Object.defineProperty(error, "errors", { value: this.errors });
 		dfd.reject(error);
 	} else {
 		dfd.resolve(this.data);


Test patch:
diff --git a/test/test.js b/test/test.js
index e185243..1f3df8d 100644
--- a/test/test.js
+++ b/test/test.js
@@ -258,6 +258,26 @@ describe("new Zone", function(){
 			}, 10);
 		});
 	});
+
+	it("catched errors should be serializable", function(done) {
+		new Zone()
+			.run(function() {
+				throw new Error("uh-oh something went wrong");
+			})
+			.then(
+				function() {
+					assert.fail("zone should not resolve");
+				},
+				function(error) {
+					try {
+						JSON.stringify(error);
+					} catch (err) {
+						assert.fail(err.message);
+					}
+				}
+			)
+			.then(done, done);
+	});
 });
 
 describe("Reusing zones", function(){