leptos-rs / cargo-leptos

Build tool for Leptos (Rust)
MIT License
314 stars 87 forks source link

The serve command returns exit code 0 when compilation fails #230

Open NiklasEi opened 4 months ago

NiklasEi commented 4 months ago

I use the serve command to build a static site. It returns when all routes are "rendered". If compilation fails, cargo leptos serve returns 0, which causes issues in my CD pipeline.

Is there any reason for the command not to fail in this case?

benwis commented 4 months ago

As I understand serve, it's not supposed to do any kind of building, it's only supposed to try and run the existing binary and other files.

Now that we have very experimental static site support, it would make sense to be able to generate those files, but I don't think anyone has thought much about that usecase for cargo-leptos.

I'd imagine you'd want a different command, or it to be part of build. Are you saying that your project compiles successfully, and then fails to create the static assets at runtime?

On Sat, Dec 30, 2023, at 2:54 AM, Niklas Eicker wrote:

I use the serve command to build a static site. It returns when all routes are "rendered". If compilation fails, cargo leptos serve returns 0, which causes issues in my CD pipeline.

Is there any reason for the command not to fail in this case?

— Reply to this email directly, view it on GitHub https://github.com/leptos-rs/cargo-leptos/issues/230, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABVBTCMY2W5DXCBM4CGPOETYL7XHZAVCNFSM6AAAAABBHODDI6VHI2DSMVQWIX3LMV43ASLTON2WKOZSGA3DANZRGIZDQNQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>

NiklasEi commented 4 months ago

The serve command actually does exactly what I need for static site generation. The name might not really fit, but the functionality is correct. It compiles the bin for the native target and the frontend for WASM. Then it runs the binary. For a SSR app the binary will start the actix/axum server. In the case of SSG, it will generate the html files of static routes.

This issue is really only about the return code of the command. Even if you use cargo leptos serve for a "normal" SSR app, and one of the two compilations fail, the command will return 0 instead of some error code.

benwis commented 4 months ago

I should say that serve building the package is at best an oversight and at worst a bug, as serve really is only supposed to serve an existing binary. Is it possible to solve your use case by running build first to catch compilation errors, and then serve? Or is there another level of runtime errors you're hoping to catch around generation?

NiklasEi commented 4 months ago

I expect serve to also build. Other tools do the same. trunk serve or cargo run also compile first if the project isn't compiled yet.

Running build before serve could be a work-around, yes.