Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler error refers to URL that doesn't exist #4437

Closed
skyrpex opened this issue Oct 6, 2023 · 1 comment · Fixed by #4452
Closed

Compiler error refers to URL that doesn't exist #4437

skyrpex opened this issue Oct 6, 2023 · 1 comment · Fixed by #4452
Assignees
Labels
🐛 bug Something isn't working ⌨️ cli CLI 🐶 dogfood Discovered while dogfooding Winglang

Comments

@skyrpex
Copy link
Contributor

skyrpex commented Oct 6, 2023

I tried this:

The actual code isn't important, but here's a way to trigger the error:

bring cloud;

class JsonApi {
  api: cloud.Api;
  pub url: str;

  init() {
    this.api = new cloud.Api();
    this.url = this.api.url;
  }

  wrapHandler(handler: inflight (cloud.ApiRequest): cloud.ApiResponse): inflight (cloud.ApiRequest): cloud.ApiResponse {
    return inflight (request) => {
      try {
        return handler(request);
      } catch error {
        return {
          status: 500,
          body: Json.stringify({
            error: error,
          }),
        };
      }
    };
  }

  pub get(path: str, handler: inflight (cloud.ApiRequest): cloud.ApiResponse) {
    this.api.get(path, this.wrapHandler(handler));
  }

  pub post(path: str, handler: inflight (cloud.ApiRequest): cloud.ApiResponse) {
    this.api.post(path, this.wrapHandler(handler));
  }

  pub put(path: str, handler: inflight (cloud.ApiRequest): cloud.ApiResponse) {
    this.api.put(path, this.wrapHandler(handler));
  }
}

let api = new JsonApi();

api.post("/route1", inflight (request) => {
  return {
    status: 200,
    body: "route1",
  };
});
api.post("/route2", inflight (request) => {
  return {
    status: 200,
    body: "route2",
  };
});

This happened:

Got this error (note the https://www.winglang.io/docs/concepts/resources URL):

Failed to compile.

ERROR: There is already a Construct with name '$Closure1' in JsonApi [JsonApi]

hint: Every preflight object needs a unique identifier within its scope. You can assign one as shown:

> new cloud.Bucket() as "MyBucket";

For more information, see https://www.winglang.io/docs/concepts/resources

Users/cristian/Code/wing.cloud/apps/@wingcloud/infrastructure/target/api.repro.main.wsim.208908.tmp/.wing/preflight.js:19
           class $Closure1 extends $stdlib.std.Resource {
             constructor(scope, id, ) {
>>             super(scope, id);
               (std.Node.of(this)).hidden = true;
             }

I expected this:

Either, the URL should work or it shouldn't refer to it.

Is there a workaround?

No response

Component

SDK

Wing Version

0.35.5

Node.js Version

No response

Platform(s)

No response

Anything else?

No response

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
@skyrpex skyrpex added the 🐛 bug Something isn't working label Oct 6, 2023
@Chriscbr Chriscbr added the ⌨️ cli CLI label Oct 6, 2023
@Chriscbr Chriscbr self-assigned this Oct 6, 2023
@mergify mergify bot closed this as completed in #4452 Oct 10, 2023
mergify bot pushed a commit that referenced this issue Oct 10, 2023
Fixes #4437

## Checklist

- [ ] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [ ] Description explains motivation and solution
- [ ] Tests added (always)
- [ ] 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)*.
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.36.7.

@staycoolcall911 staycoolcall911 added the 🐶 dogfood Discovered while dogfooding Winglang label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working ⌨️ cli CLI 🐶 dogfood Discovered while dogfooding Winglang
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants