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] Type Error when used defineMetadataSchema and handleServerError together. #333

Open
2 tasks done
yourcodebuddy-in opened this issue Mar 13, 2025 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@yourcodebuddy-in
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

I am trying to log errors to Posthog using handleServerError, and it worked. But I needed a few more details, like the file and action name. I think using metadata can be a good option.

So created a new action client using this code.

export const actionClient = createSafeActionClient({
  handleServerError: (error, utils) => {
    // Log error to Posthog
  },
  defineMetadataSchema() {
    return z.object({
      file: z.string(),
      actionName: z.string(),
    });
  },
});

This works and I can use the metadata values but the types have some issues.

If I don't add utils in this line handleServerError: (error, utils) => {, then types work correctly. But if I add utils then types don't work. Everywhere where I am pass metadata starts to give errors. I have attached a video please take a look.

Recording.2025-03-13.081706.mov

Reproduction steps

Create a new action client with two functions handleServerError and defineMetadataSchema and use metadata inside the handleServerError function.

Expected behavior

The types should work fine even when I use metadata inside the handleServerError function.

Link to a minimal reproduction of the issue

https://github.com/yourcodebuddy-in/next-safe-action-bug.git

Operating System

Windows 11

Library version

7.10.4

Next.js version

15.2.2

Node.js version

22.13.1

Additional context

No response

@yourcodebuddy-in yourcodebuddy-in added the bug Something isn't working label Mar 13, 2025
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