From 9b360dd5a9339dae3d1fff1bd89559671d96116c Mon Sep 17 00:00:00 2001 From: Ansgar Mertens Date: Fri, 23 Jun 2023 15:11:21 +0200 Subject: [PATCH 1/2] fix(cli): catch possible errors when trying to open a url Resolves #2936 --- .../src/bin/cmds/helper/terraform-login.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/cdktf-cli/src/bin/cmds/helper/terraform-login.ts b/packages/cdktf-cli/src/bin/cmds/helper/terraform-login.ts index f709f30637..ac44fc00a0 100644 --- a/packages/cdktf-cli/src/bin/cmds/helper/terraform-login.ts +++ b/packages/cdktf-cli/src/bin/cmds/helper/terraform-login.ts @@ -52,17 +52,27 @@ the following file for use by subsequent Terraform commands: if (tfCloud) { isLogin = true; - this.openBrowser(); + await this.openBrowser(); } return isLogin; } - openBrowser() { + async openBrowser() { console.log(`\nopening webpage using your browser.....\n`); console.log(chalkColour`If the web browser didn't open the window automatically, you can go to the following url: {whiteBright ${this.terraformLoginURL}}\n`); - return open.default(this.terraformLoginURL); + try { + await open.default(this.terraformLoginURL, { + allowNonzeroExitCode: true, + wait: true, + }); + } catch (e) { + logger.debug( + `Ignored error while trying to open ${this.terraformLoginURL}`, + e + ); + } } public async askForToken() { From cedf0bf5e2a86a509d43a327c58dfd95f66c3408 Mon Sep 17 00:00:00 2001 From: Ansgar Mertens Date: Fri, 23 Jun 2023 15:31:51 +0200 Subject: [PATCH 2/2] fix(tests): update convert command unit tests related to #2946 --- .../cdktf-cli/src/test/cmds/convert.test.ts | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/packages/cdktf-cli/src/test/cmds/convert.test.ts b/packages/cdktf-cli/src/test/cmds/convert.test.ts index a35256bc10..50c15656ad 100644 --- a/packages/cdktf-cli/src/test/cmds/convert.test.ts +++ b/packages/cdktf-cli/src/test/cmds/convert.test.ts @@ -27,11 +27,9 @@ describe("convert command", () => { `The following providers are missing schema information and might need manual adjustments to synthesize correctly` ); expect(result.stdout).toContain( - `import * as NullProvider from "./.gen/providers/null";` - ); - expect(result.stdout).toContain( - `new NullProvider.resource.Resource(this, "dummy", {});` + `import { Resource } from "./.gen/providers/null/resource";` ); + expect(result.stdout).toContain(`new Resource(this, "dummy", {});`); }); }, 30_000); it("reads provider version from existing cdktf.json", async () => { @@ -50,11 +48,9 @@ describe("convert command", () => { `The following providers are missing schema information and might need manual adjustments to synthesize correctly` ); expect(result.stdout).toContain( - `import * as NullProvider from "./.gen/providers/null";` - ); - expect(result.stdout).toContain( - `new NullProvider.resource.Resource(this, "dummy", {});` + `import { Resource } from "./.gen/providers/null/resource";` ); + expect(result.stdout).toContain(`new Resource(this, "dummy", {});`); }); }, 30_000); it("works if no cdktf.json could be found", async () => { @@ -69,11 +65,9 @@ describe("convert command", () => { `The following providers are missing schema information and might need manual adjustments to synthesize correctly` ); expect(result.stdout).toContain( - `import * as NullProvider from "./.gen/providers/null";` - ); - expect(result.stdout).toContain( - `new NullProvider.resource.Resource(this, "dummy", {});` + `import { Resource } from "./.gen/providers/null/resource";` ); + expect(result.stdout).toContain(`new Resource(this, "dummy", {});`); }); }, 30_000); @@ -134,11 +128,9 @@ describe("convert command", () => { `The following providers are missing schema information and might need manual adjustments to synthesize correctly` ); expect(result.stdout).toContain( - `import * as kubernetes from "./.gen/providers/kubernetes";` - ); - expect(result.stdout).toContain( - `new kubernetes.deployment.Deployment(this, "myapp", {` + `import { Deployment } from "./.gen/providers/kubernetes/deployment";` ); + expect(result.stdout).toContain(`new Deployment(this, "myapp", {`); expect(result.stdout).toContain(`template: {`); }); }, 30_000); @@ -200,11 +192,9 @@ describe("convert command", () => { `The following providers are missing schema information and might need manual adjustments to synthesize correctly` ); expect(result.stdout).toContain( - `import * as kubernetes from "./.gen/providers/kubernetes";` - ); - expect(result.stdout).toContain( - `new kubernetes.deployment.Deployment(this, "myapp", {` + `import { Deployment } from "./.gen/providers/kubernetes/deployment";` ); + expect(result.stdout).toContain(`new Deployment(this, "myapp", {`); expect(result.stdout).toContain(`template: {`); }); }, 30_000);