sqlx-ts icon indicating copy to clipboard operation
sqlx-ts copied to clipboard

Types are not generated on the first run. No such file or directory

Open Leo5878 opened this issue 1 year ago • 1 comments

I am running sqlx-ts for the first time; the type file does not exist yet, and the types are being generated. The file already exists, and the types need to be updated. After running the command "command", the file is deleted, and an error occurs:

$ sqlx-ts ./src/model/ -g --config .sqlxrc.json --generate-path ./src/model/types.ts
[INFO] Scanning "./src/model/" for SQLs with extension Ts
thread 'main' panicked at src/parser/mod.rs:133:45:
called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error Command failed with exit code 101.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Process finished with exit code 101

But on re-running the command, the file is created again, and the types are generated again.

Leo5878 avatar May 18 '24 20:05 Leo5878

Thanks for reporting, that is strange - I will take a look soon. Can you try without --generate-path in the meantime?

JasonShin avatar May 19 '24 03:05 JasonShin

Unfortunately, i can't(

Leo5878 avatar Jun 04 '24 21:06 Leo5878

@Leo5878 hello, I'm trying to reproduce this issue.

I am trying multiple ways to run sqlx-ts based on your explanations

  • for generate-path, when I give it a file path that does not exist yet (for example ./tests/stagingz/hello.types.ts). I can see it correctly creates the non-existing folder and the type definition under the folder as well.
  • I am only seeing the same error in the issue if I provide a wrong path to typescript or javascript project Screen Shot 2024-06-10 at 11 18 30 am ^^^ in this example, I am intentionally providing ./tests/stagingz which does not exist

If this is the case, I can go ahead and enhance the error message when you provide a project path that does not exist


Actually nvm, we already have the a line to check for an empty project here https://github.com/JasonShin/sqlx-ts/blob/main/src/main.rs#L49

JasonShin avatar Jun 10 '24 01:06 JasonShin

This is now released as 0.12.1 https://github.com/JasonShin/sqlx-ts/releases/tag/v0.12.1

JasonShin avatar Jun 10 '24 01:06 JasonShin

@JasonShin Hi! No, that's not quite right. According to my tests, the level of nesting somehow affects this issue. I couldn't understand why, but during debugging, I noticed that scanfolder returns the file specified in generate-path, not all the files with the .ts extension in the folder. After running it again, it returns all the files. Somehow, my PR managed to fix this problem. I will try to study the issue further in the future if I have the opportunity.

Thank you for accepting my PR!

Leo5878 avatar Jun 10 '24 07:06 Leo5878

Thanks, I have added my thought in https://github.com/JasonShin/sqlx-ts/pull/114, thanks for this

JasonShin avatar Jun 10 '24 08:06 JasonShin