oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.28k stars 2.77k forks source link

TypeError: FormData parse error missing final boundary #4161

Closed CodeFromAnywhere closed 9 months ago

CodeFromAnywhere commented 1 year ago

What version of Bun is running?

0.7.3

What platform is your computer?

Linux 5.15.0-60-generic x86_64 x86_64

What steps can reproduce the bug?

I'm using Bun.servewith therequest.formData`

I'm using sendgrid to receive emails in bun but Sendgrid is apparently not giving FormData dat you can parse. Somehow, sometimes it works, sometimes it doesn't.

Before I go more in-depth... maybe you can look at your request.formData() or let me know how to use it?

Makes it very difficult to get the files of attachments of emails in sendgrid.

What is the expected behavior?

It should parse it even without boundary

What do you see instead?

It throws TypeError: FormData parse error missing final boundary

Additional information

My code:

export const tryGetFormData = async (request: Request | undefined) => {
  try {
    return request?.clone().formData();
  } catch (e) {
    return undefined;
  }
};

It Throws with Sendgrid incoming mail

CodeFromAnywhere commented 1 year ago

How can I help debug this? Maybe do you need the raw body and headers?

paperdave commented 1 year ago

this is just a guess but maybe it is be that .clone() and .formData() don't work together. can you try this like request?.formData()?

CodeFromAnywhere commented 1 year ago

this is just a guess but maybe it is be that .clone() and .formData() don't work together. can you try this like request?.formData()?

Nah, it seems to be the same. Doesn't clone just create a copy of request so you can do things twice?

EDIT: Weird, you seem to be right. The problem has gone away.

ZiNai commented 9 months ago

I use Bun(1.0.25) run qwik.js start docs . I click the vote button. expect console log the form inputs, but triggered this bug.

import { component$ } from '@builder.io/qwik';
import { routeLoader$, Form, routeAction$ } from '@builder.io/qwik-city';

export const useJokeVoteAction = routeAction$((props) => {
  // Leave it as an exercise for the reader to implement this.
  console.log('VOTE', props);
});
export const useDadJoke = routeLoader$(async () => {
  const response = await fetch('https://icanhazdadjoke.com/', {
    headers: { Accept: 'application/json' },
  });
  return (await response.json()) as {
    id: string;
    status: number;
    joke: string;
  };
});

export default component$(() => {
    const dadJokeSignal = useDadJoke();
    const favoriteJokeAction = useJokeVoteAction();
    return (
      <section class="section bright">
        <p>{dadJokeSignal.value.joke}</p>
        <Form action={favoriteJokeAction}>
          <input type="hidden" name="jokeID" value={dadJokeSignal.value.id} />
          <button name="vote" value="up">👍</button>
          <button name="vote" value="down">👎</button>
        </Form>
      </section>
    );
  });

CleanShot 2024-01-24 at 00 03 38@2x

This is deps:

"devDependencies": {
    "@builder.io/qwik": "^1.4.0",
    "@builder.io/qwik-city": "^1.4.0",
    "@types/eslint": "^8.56.2",
    "@types/node": "^20.11.0",
    "@typescript-eslint/eslint-plugin": "^6.18.1",
    "@typescript-eslint/parser": "^6.18.1",
    "eslint": "^8.56.0",
    "eslint-plugin-qwik": "^1.4.0",
    "prettier": "^3.1.1",
    "typescript": "5.3.3",
    "undici": "*",
    "vite": "^5.0.11",
    "vite-tsconfig-paths": "^4.2.1"
  }
Electroid commented 9 months ago

Duplicate of #2644