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

Event was rejected by relay on publish but promise resolved #142

Open
yijiasu opened this issue Nov 28, 2023 · 2 comments
Open

Event was rejected by relay on publish but promise resolved #142

yijiasu opened this issue Nov 28, 2023 · 2 comments

Comments

@yijiasu
Copy link

yijiasu commented Nov 28, 2023

➜  relay git:(main) ✗ DEBUG=ndk:* ts-node seed/index.ts
  ndk:pool Connecting to 1 relays +0ms
  ndk:pool Relay ws://localhost:10801 connected +13ms
  ndk:relay:ws://localhost:10801 Publish failed Error: invalid: unexpected size for fixed-size tag
    at Timeout.handleNext (/Users/******/node_modules/.pnpm/[email protected][email protected]/node_modules/nostr-tools/lib/cjs/index.js:549:27)
    at listOnTimeout (node:internal/timers:573:17)
    at processTimers (node:internal/timers:514:7) 49c4aa1cf2ab81d99fd94d07ed53cb2f1da57bec307c6edd7a04ea469f49e80e +0ms
PUBLISH SUCCESS

Some code snippet:

  const ndk = new NDK({ explicitRelayUrls: ["ws://localhost:10801"] });

  const ndkEvent = new NDKEvent(ndk, json2);

  await ndk.connect();
  try {
    const out = await ndkEvent.publish();
    console.log("PUBLISH SUCCESS");
  } catch (error) {
    console.log("error");
    console.log(error);
  }

Version:

    "@nostr-dev-kit/ndk": "2.1.1",
@yijiasu
Copy link
Author

yijiasu commented Nov 28, 2023

Looks like it's resolved because of the event was an ephemeral one, so the error was ignored? Is there a reason we should swallow the error here instead of forwarding this exception to the user space?

@yijiasu
Copy link
Author

yijiasu commented Nov 29, 2023

Here:

public async publish(event: NDKEvent, timeoutMs?: number): Promise<Set<NDKRelay>> {
const publishedToRelays: Set<NDKRelay> = new Set();
const isEphemeral = event.isEphemeral();
// go through each relay and publish the event
const promises: Promise<void>[] = Array.from(this.relays).map((relay: NDKRelay) => {
return new Promise<void>((resolve) => {
relay
.publish(event, timeoutMs)
.then(() => {
publishedToRelays.add(relay);
resolve();
})
.catch((err) => {
if (!isEphemeral) {
this.debug("error publishing to relay", {
relay: relay.url,
err,
});
}
resolve();
});
});
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant