winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.97k stars 196 forks source link

Running `wing it` gives error "connections.json not found" #5693

Open Chriscbr opened 7 months ago

Chriscbr commented 7 months ago

I tried this:

Running wing it on my Wing file that was named hello.w

This happened:

Wing Console opens, but it shows the error:

Invalid Wing app (/Users/chrisr/dev/wing-test/target/hello.wsim) - connections.json not found.

I expected this:

An error (either in Wing Console, or in the CLI) saying that it's not a valid entrypoint file. The file must be named main.w or end in .main.w or .test.w

Is there a workaround?

No response

Anything else?

No response

Wing Version

0.57.29

Node.js Version

20.9.0

Platform(s)

MacOS

Community Notes

skyrpex commented 2 months ago

This only happens if the hello.w file is a valid wing module file (meaning, only contains bring statements and declarations). For example:

bring cloud;

or

class Example {}

If the file contains new expressions, for example, it will trigger a compilation error and work as expected:

class Example {}
new Example();
Failed to compile.

error: Module files cannot have statements besides classes, interfaces, enums, and structs. Rename the file to end with `.main.w` or `.test.w` to make this an entrypoint file.
  --> hello.w:3:1
  |
3 | new Lol();
  | ^^^^^^^^^^

Yeah, I wonder whose responsibility is this.

On one hand, I'd assume that after compiling any wing file (main or otherwise), we would get a valid hello.wsim directory. Currently, the directory is generated but the connections.json file is missing. I think we should fix that, independently on whether we also forbid wing'ing it on resources that aren't main files.

On the other hand, I kind of guess that it makes sense to forbid starting wing files that aren't main files. That could be fixed editing apps/wing/src/commands/run.ts and running a small check.

TLDR; I think this issue should be converted into two! One for the compiler (or sdk?) and another for the CLI package.