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

[BUG] Uncaught exception when body size exceeds bodySizeLimit #301

Open
2 tasks done
aymericfontaine opened this issue Nov 24, 2024 · 1 comment
Open
2 tasks done
Labels
bug Something isn't working

Comments

@aymericfontaine
Copy link

Are you using the latest version of this library?

  • I verified that the issue exists in the latest next-safe-action release

Is there an existing issue for this?

  • I have searched the existing issues and found nothing that matches

Describe the bug

When calling a server action with a request body size exceeding 1 MB (as limited by the bodySizeLimit in serverActions), the error is not caught by error.serverError. Instead, it throws an uncaught exception, breaking the expected error handling flow.

Reproduction steps

  1. Set up a server action using next-safe-action.
  2. Send a request with a body larger than 1 MB.
  3. Observe that the error is not handled by error.serverError and instead throws an uncaught exception.

Expected behavior

When the request body size exceeds the limit, the error should be caught and processed by error.serverError, ensuring consistent error handling and avoiding unhandled exceptions.

Link to a minimal reproduction of the issue

https://github.com/aymericfontaine/reprod-nextsafeaction-bodysizelimit

Operating System

macOS

Library version

7.9.9

Next.js version

15.0.3

Node.js version

20.15.0

Additional context

No response

@aymericfontaine aymericfontaine added the bug Something isn't working label Nov 24, 2024
@TheEdoRan
Copy link
Owner

TheEdoRan commented Dec 9, 2024

Thank you for providing a repro. I took a look at it and tried to define an action without using next-safe-action, and the same happens.

"use server";

export const sendFile2 = async (file: File) => {
  try {
    console.log("file", file.name);
    return { success: true };
  } catch (err) {
    console.log("Caught error!", err);
    return { success: false };
  }
};

When the body size limit error occurs, the catch block is never reached, even without next-safe-action defined actions:
image

This means there's no way for this library to catch that error (or at least, I haven't found any way), because it seems to be thrown at a higher level. I expected this behavior because next-safe-action catches all server errors and puts them inside the serverError prop, except from the framework ones that need to be rethrown (like navigation errors).

So I don't think there's a way to catch this error, but if I (or you, or someone else) find it, I'll then implement it.

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

2 participants