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

Parsing malformed body results in UNKNOWN-Error instead of ParseError #973

Closed
bogeychan opened this issue Dec 24, 2024 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@bogeychan
Copy link
Contributor

What version of Elysia is running?

1.2.2

What platform is your computer?

WSL Ubuntu

What steps can reproduce the bug?

// test.test.ts
import { test, expect } from "bun:test";
import { Elysia, t } from "elysia";

test("Should get parse error code", async () => {
  let code: string | undefined;

  const app = new Elysia()
    .onError((ctx) => {
      code = ctx.code;
    })
    .post("/", () => "", {
      body: t.Object({
        test: t.String(),
      }),
    });

  await app.modules;

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

  expect(code).toBe("PARSE");
  expect(response.status).toBe(400);
});

bun test

What is the expected behavior?

test pass

What do you see instead?

test fail:

test.test.ts:
27 | }
28 | delete c.contentType
29 | isParsing=false
30 | c.body=validator.body.Clean(c.body)
31 | if(validator.body.Check(c.body)===false){c.set.status=422;throw new ValidationError('body',validator.body,c.body)}return mapCompactResponse(handler(c),c.request.signal)
32 | }catch(error){if(isParsing)error=new ParseError()
                               ^
ReferenceError: Can't find variable: isParsing

Additional information

this used to work back in 1.1.27

Have you try removing the node_modules and bun.lockb and try again yet?

yes

@bogeychan bogeychan added the bug Something isn't working label Dec 24, 2024
@bogeychan bogeychan changed the title Parsing invalid body results in InternalServerError instead of ParseError Parsing invalid body results in UNKNOWN-Error instead of ParseError Dec 24, 2024
@bogeychan bogeychan changed the title Parsing invalid body results in UNKNOWN-Error instead of ParseError Parsing malformed body results in UNKNOWN-Error instead of ParseError Dec 24, 2024
@SaltyAom
Copy link
Member

SaltyAom commented Dec 24, 2024

Fixed in e83daaf, published under 1.2.3

@kravetsone
Copy link
Contributor

I love how u write reproduces as tests huh

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

3 participants