Skip to content

Commit

Permalink
fix(sdk): better error message on unsupported compile target (#4282)
Browse files Browse the repository at this point in the history
closes #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)*.
  • Loading branch information
exoego authored Sep 26, 2023
1 parent 6a18060 commit 380c161
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion libs/wingsdk/src/core/app.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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}`
);
}

Expand Down
9 changes: 5 additions & 4 deletions libs/wingsdk/test/core/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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/
);
});

Expand All @@ -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 });
Expand Down

0 comments on commit 380c161

Please sign in to comment.