@@ -23,6 +23,31 @@ ruleTester.run("preserve-caught-error", rule, {
2323 } catch (error) {
2424 throw new Error("Failed to perform error prone operations", { cause: error });
2525 }` ,
26+ `try {
27+ doSomething();
28+ } catch (error) {
29+ throw new Error("Something failed", { 'cause': error });
30+ }` ,
31+ `try {
32+ doSomething();
33+ } catch (error) {
34+ throw new Error("Something failed", { "cause": error });
35+ }` ,
36+ `try {
37+ doSomething();
38+ } catch (error) {
39+ throw new Error("Something failed", { ['cause']: error });
40+ }` ,
41+ `try {
42+ doSomething();
43+ } catch (error) {
44+ throw new Error("Something failed", { ["cause"]: error });
45+ }` ,
46+ `try {
47+ doSomething();
48+ } catch (error) {
49+ throw new Error("Something failed", { [\`cause\`]: error });
50+ }` ,
2651 /* No throw inside catch */
2752 `try {
2853 doSomething();
@@ -92,6 +117,16 @@ ruleTester.run("preserve-caught-error", rule, {
92117 } catch (error) {
93118 throw new Error("Something failed", { cause: anotherError, cause: error });
94119 }` ,
120+ `try {
121+ doSomething();
122+ } catch (error) {
123+ throw new Error("Something failed", { "cause": anotherError, "cause": error });
124+ }` ,
125+ `try {
126+ doSomething();
127+ } catch (error) {
128+ throw new Error("Something failed", { cause: anotherError, "cause": error });
129+ }` ,
95130 ] ,
96131 invalid : [
97132 /* 1. Throws a new Error without cause, even though an error was caught */
@@ -136,6 +171,30 @@ ruleTester.run("preserve-caught-error", rule, {
136171 } catch (err) {
137172 const unrelated = new Error("other");
138173 throw new Error("Something failed", { cause: err });
174+ }` ,
175+ } ,
176+ ] ,
177+ } ,
178+ ] ,
179+ } ,
180+ {
181+ code : `try {
182+ doSomething();
183+ } catch (err) {
184+ const unrelated = new Error("other");
185+ throw new Error("Something failed", { "cause": unrelated });
186+ }` ,
187+ errors : [
188+ {
189+ messageId : "incorrectCause" ,
190+ suggestions : [
191+ {
192+ messageId : "includeCause" ,
193+ output : `try {
194+ doSomething();
195+ } catch (err) {
196+ const unrelated = new Error("other");
197+ throw new Error("Something failed", { "cause": err });
139198 }` ,
140199 } ,
141200 ] ,
@@ -735,6 +794,12 @@ ruleTester.run("preserve-caught-error", rule, {
735794 }` ,
736795 errors : [ { messageId : "incorrectCause" } ] ,
737796 } ,
797+ {
798+ code : `try {} catch (error) {
799+ throw new Error("Something failed", { cause: error, "cause": anotherError });
800+ }` ,
801+ errors : [ { messageId : "incorrectCause" } ] ,
802+ } ,
738803 /* 26. Getters and setters as `cause`. */
739804 {
740805 code : `try {} catch (error) {
0 commit comments