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

aot does not recognize the use of ctx.body within a try catch #658

Closed
bogeychan opened this issue May 27, 2024 · 1 comment
Closed

aot does not recognize the use of ctx.body within a try catch #658

bogeychan opened this issue May 27, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@bogeychan
Copy link
Contributor

bogeychan commented May 27, 2024

What version of Elysia.JS is running?

1.0.22

What platform is your computer?

WSL Ubuntu

What steps can reproduce the bug?

// test.test.ts
import { describe, it, expect } from "bun:test";
import { Elysia, type Context } from "elysia";

describe("AOT", () => {
  it("???", async () => {
    class Controller {
      static async handle(ctx: Context) {
        try {
          // @ts-ignore
          const { token } = ctx.body;
          return token;
        } catch {
          return "nope";
        }
      }
    }

    const app = new Elysia({ aot: true }).post("/", Controller.handle);

    const response = await app.handle(
      new Request("http://localhost/", {
        method: "POST",
        body: JSON.stringify({ token: "yay" }),
        headers: { "Content-Type": "application/json" },
      })
    );

    expect(await response.text()).toEqual("yay");
  });
});

What is the expected behavior?

Pass all tests

What do you see instead?

Expected: "yay"
Received: "nope"

Additional information

workaround:

new Elysia({ aot: false })

reported on discord

@bogeychan bogeychan added the bug Something isn't working label May 27, 2024
@bogeychan
Copy link
Contributor Author

Looks like its related to this: #656

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant