From 380c161a2996efe1f481e6efc86e768bf05cdb6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TATSUNO=20=E2=80=9CTaz=E2=80=9D=20Yasuhiro?= Date: Tue, 26 Sep 2023 23:41:08 +0900 Subject: [PATCH] fix(sdk): better error message on unsupported compile target (#4282) closes https://github.com/winglang/wing/issues/4172 The new error message tells that the resource still needs to be implemented for the target. It also includes a link to the roadmap with a filter, so user can find the ticket for the implementation Before | After ---|--- Unable to create an instance of abstract type "@winglang/sdk.cloud.Api" for this target | Resource "@winglang/sdk.cloud.Api" is not yet implemented for "awscdk" target. Please refer to the roadmap https://github.com/orgs/winglang/projects/3/views/1?filterQuery=cloud.Api ## Checklist - [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [x] Description explains motivation and solution - [x] Tests added (always) - [x] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*. --- libs/wingsdk/src/core/app.ts | 4 +++- libs/wingsdk/test/core/app.test.ts | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/wingsdk/src/core/app.ts b/libs/wingsdk/src/core/app.ts index 8988cf390da..f8de6784dfa 100644 --- a/libs/wingsdk/src/core/app.ts +++ b/libs/wingsdk/src/core/app.ts @@ -1,5 +1,6 @@ import { Construct } from "constructs"; import { Tokens } from "./tokens"; +import { SDK_PACKAGE_NAME } from "../constants"; import { IResource } from "../std/resource"; import { TestRunner } from "../std/test-runner"; @@ -189,9 +190,10 @@ export abstract class App extends Construct { ): any { // delegate to "tryNew" first, which will allow derived classes to inject const instance = this.tryNew(fqn, scope, id, ...args); + const typeName = fqn.replace(`${SDK_PACKAGE_NAME}.`, ""); if (!instance) { throw new Error( - `Unable to create an instance of abstract type \"${fqn}\" for this target` + `Resource "${fqn}" is not yet implemented for "${this._target}" target. Please refer to the roadmap https://github.com/orgs/winglang/projects/3/views/1?filterQuery=${typeName}` ); } diff --git a/libs/wingsdk/test/core/app.test.ts b/libs/wingsdk/test/core/app.test.ts index 28e87634fd4..1f1d56144ab 100644 --- a/libs/wingsdk/test/core/app.test.ts +++ b/libs/wingsdk/test/core/app.test.ts @@ -8,9 +8,9 @@ import { App as TfAwsApp } from "../../src/target-tf-aws/app"; import { App as TfAzureApp } from "../../src/target-tf-azure/app"; import { App as TfGcpApp } from "../../src/target-tf-gcp/app"; -const FOO_FQN = "@lib/foo.Foo"; -const BAR_FQN = "@lib/foo.Bar"; -const ANOTHER_FQN = "@lib/another.Another"; +const FOO_FQN = "@winglang/sdk.foo.Foo"; +const BAR_FQN = "@winglang/sdk.foo.Bar"; +const ANOTHER_FQN = "@winglang/sdk.another.Another"; test("new() allows derived classes to inject a different implementation", () => { const app = new MyApp(); @@ -34,7 +34,7 @@ test("new() defaults to just creating an instance", () => { test("newAbstract() throws if there is no implementation", () => { const app = new MyApp(); expect(() => app.newAbstract(ANOTHER_FQN, app, "bar")).toThrow( - /Unable to create an instance of abstract type \"@lib\/another.Another\" for this target/ + /Resource \"@winglang\/sdk\.another.Another\" is not yet implemented for "awscdk" target\. Please refer to the roadmap https:\/\/github\.com\/orgs\/winglang\/projects\/3\/views\/1\?filterQuery=another\.Another/ ); }); @@ -59,6 +59,7 @@ class MyApp extends App { public outdir: string = "outdir"; public isTestEnvironment: boolean = true; public readonly _tokens: Tokens; + public readonly _target = "awscdk"; constructor() { super(undefined as any, "MyApp", { entrypointDir: __dirname });