From d44acf51ed142101c7d39fbf4cff5ef73f8f5088 Mon Sep 17 00:00:00 2001 From: Robin Tail Date: Sat, 2 Nov 2024 10:23:52 +0100 Subject: [PATCH 1/4] Drop originalError prop. --- src/errors.ts | 16 ---------------- tests/unit/errors.spec.ts | 2 -- 2 files changed, 18 deletions(-) diff --git a/src/errors.ts b/src/errors.ts index c656c019b..ce4c8fbf5 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -41,14 +41,6 @@ export class OutputValidationError extends IOSchemaError { constructor(public override readonly cause: z.ZodError) { super(getMessageFromError(cause), { cause }); } - - /** - * @deprecated use the cause property instead - * @todo remove in v21 - * */ - public get originalError() { - return this.cause; - } } /** @desc An error of validating the input sources against the Middleware or Endpoint input schema */ @@ -58,14 +50,6 @@ export class InputValidationError extends IOSchemaError { constructor(public override readonly cause: z.ZodError) { super(getMessageFromError(cause), { cause }); } - - /** - * @deprecated use the cause property instead - * @todo remove in v21 - * */ - public get originalError() { - return this.cause; - } } /** @desc An error related to the execution or incorrect configuration of ResultHandler */ diff --git a/tests/unit/errors.spec.ts b/tests/unit/errors.spec.ts index f3af1861f..405a750f0 100644 --- a/tests/unit/errors.spec.ts +++ b/tests/unit/errors.spec.ts @@ -69,7 +69,6 @@ describe("Errors", () => { test("should have .cause property matching the one used for constructing", () => { expect(error.cause).toEqual(zodError); - expect(error.originalError).toEqual(zodError); }); }); @@ -88,7 +87,6 @@ describe("Errors", () => { test("should have .cause property matching the one used for constructing", () => { expect(error.cause).toEqual(zodError); - expect(error.originalError).toEqual(zodError); }); }); From 774f1ef63b3126c739560eec1716d894ac0c16b1 Mon Sep 17 00:00:00 2001 From: Robin Tail Date: Sat, 2 Nov 2024 11:51:44 +0100 Subject: [PATCH 2/4] Add migration. --- src/migration.ts | 24 +++++++++++++++++++++++- tests/unit/migration.spec.ts | 11 +++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/migration.ts b/src/migration.ts index cdd764520..4418e39b9 100644 --- a/src/migration.ts +++ b/src/migration.ts @@ -10,11 +10,13 @@ const createServerName = "createServer"; const serverPropName = "server"; const httpServerPropName = "httpServer"; const httpsServerPropName = "httpsServer"; +const originalErrorPropName = "originalError"; const changedProps = { [serverPropName]: "http", [httpServerPropName]: "servers", [httpsServerPropName]: "servers", + [originalErrorPropName]: "cause", }; const movedProps = [ @@ -57,7 +59,27 @@ const v21 = ESLintUtils.RuleCreator.withoutDocs({ }, defaultOptions: [], create: (ctx) => ({ - CallExpression: (node) => { + [NT.MemberExpression]: (node) => { + if ( + node.property.type === NT.Identifier && + node.property.name === originalErrorPropName && + node.object.type === NT.Identifier && + node.object.name.match(/err/i) // this is most likely an error instance + ) { + const replacement = changedProps[node.property.name]; + ctx.report({ + node: node.property, + messageId: "change", + data: { + subject: "property", + from: node.property.name, + to: replacement, + }, + fix: (fixer) => fixer.replaceText(node.property, replacement), + }); + } + }, + [NT.CallExpression]: (node) => { if (node.callee.type !== NT.Identifier) return; if ( node.callee.name === createConfigName && diff --git a/tests/unit/migration.spec.ts b/tests/unit/migration.spec.ts index a90fd0542..f7b8d07c8 100644 --- a/tests/unit/migration.spec.ts +++ b/tests/unit/migration.spec.ts @@ -24,6 +24,7 @@ tester.run("v21", migration.rules.v21, { `createConfig({ http: {} });`, `createConfig({ http: { listen: 8090 }, upload: true });`, `const { app, servers, logger } = await createServer();`, + `const error = new Error(); console.error(error.cause?.message);`, ], invalid: [ { @@ -63,5 +64,15 @@ tester.run("v21", migration.rules.v21, { }, ], }, + { + code: `const error = new Error(); console.error(error.originalError?.message);`, + output: `const error = new Error(); console.error(error.cause?.message);`, + errors: [ + { + messageId: "change", + data: { subject: "property", from: "originalError", to: "cause" }, + }, + ], + }, ], }); From 64df9e1cdd9ff5e5d2fca1736ca69f3e1468cd6c Mon Sep 17 00:00:00 2001 From: Robin Tail Date: Sat, 2 Nov 2024 11:52:54 +0100 Subject: [PATCH 3/4] Changelog: note on removed prop. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8368a6f9..44949fe1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Properties `httpServer` and `httpsServer` are removed; - Added `servers` property — array containing those server instances in the same order. - The `serializer` property of `Documentation` and `Integration` constructor argument removed; +- The `originalError` property of `InputValidationError` and `OutputValidationError` removed (use `cause` instead); - Consider the automated migration using the built-in ESLint rule. ```js From c36c00be53f014ba326cfda32b65ead27587b7dc Mon Sep 17 00:00:00 2001 From: Robin Tail Date: Sat, 2 Nov 2024 12:30:13 +0100 Subject: [PATCH 4/4] No auto fix because we don't do type checking to be sure. --- src/migration.ts | 3 +-- tests/unit/migration.spec.ts | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/migration.ts b/src/migration.ts index 4418e39b9..8c5c1dbf1 100644 --- a/src/migration.ts +++ b/src/migration.ts @@ -64,7 +64,7 @@ const v21 = ESLintUtils.RuleCreator.withoutDocs({ node.property.type === NT.Identifier && node.property.name === originalErrorPropName && node.object.type === NT.Identifier && - node.object.name.match(/err/i) // this is most likely an error instance + node.object.name.match(/err/i) // this is probably an error instance, but we don't do type checking ) { const replacement = changedProps[node.property.name]; ctx.report({ @@ -75,7 +75,6 @@ const v21 = ESLintUtils.RuleCreator.withoutDocs({ from: node.property.name, to: replacement, }, - fix: (fixer) => fixer.replaceText(node.property, replacement), }); } }, diff --git a/tests/unit/migration.spec.ts b/tests/unit/migration.spec.ts index f7b8d07c8..b3ae98954 100644 --- a/tests/unit/migration.spec.ts +++ b/tests/unit/migration.spec.ts @@ -66,7 +66,6 @@ tester.run("v21", migration.rules.v21, { }, { code: `const error = new Error(); console.error(error.originalError?.message);`, - output: `const error = new Error(); console.error(error.cause?.message);`, errors: [ { messageId: "change",