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

Show error or throw error on emit('event', { some: 'data' }) #52

Closed
bluepuma77 opened this issue Jul 17, 2024 · 2 comments
Closed

Show error or throw error on emit('event', { some: 'data' }) #52

bluepuma77 opened this issue Jul 17, 2024 · 2 comments
Labels
seen I've seen and read this issue and I'll try find some time soon to work on it.

Comments

@bluepuma77
Copy link

When using emit('event', { some: 'data' }), it seems nothing is sent to the client, and no error message is shown or thrown.

It would be great if a notice would be provided to the developer that they use wrong parameter format.

@razshare razshare added the seen I've seen and read this issue and I'll try find some time soon to work on it. label Jul 17, 2024
@razshare
Copy link
Owner

razshare commented Jul 17, 2024

Hello @bluepuma77 ,
emit() doesn't throw errors, it returns Unsafe<void>, which is an Either<L,R> in disguise, in this case L being void and R an Error.

import { produce } from 'sveltekit-sse';

export function POST() {
  return produce(async function start({ emit }) {
    while (true) {
      const { error } = await emit('event', { some: 'data' });
      if (error) {
        console.error(`There's been an error.\n${error.message}`);
        return;
      }
    }
  });
}

image

When it comes to static analysis, I'm getting a type error as expected -
image

Let me know if this solves your issue.

@razshare
Copy link
Owner

razshare commented Aug 2, 2024

I'm closing this issue due to inactivity.
Feel free to open another issue or follow up here if you think it should be reopened.

@razshare razshare closed this as completed Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
seen I've seen and read this issue and I'll try find some time soon to work on it.
Projects
None yet
Development

No branches or pull requests

2 participants