Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
failed to read stream, no exist StreamNotFoundError: stream not found

As per documentation:

https://developers.eventstore.com/clients/grpc/reading-events.html#reading-backwards-1

under: Checking if the stream exists

const events = client.readStream("user", {
  direction: FORWARDS,
  fromRevision: BigInt(10),
  maxCount: 20,
});

try {
  for await (const resolvedEvent of events) {
    console.log(resolvedEvent.event?.data);
  }
} catch (error) {
  if (error instanceof StreamNotFoundError) {
    return;
  }

  throw error;
}

i do get:

failed to read stream, no exist StreamNotFoundError: user not found

Their tutorials seems outdated for me.

Q: Is there a way to check if a stream exist ( and maybe add if not?) in event store in 2022?

Edit 2:

after the attempts, it still shows with the provided answer: node:events:505 throw er; // Unhandled 'error' event ^

StreamNotFoundError: user not found
    at ReadStream._transform (game\node_modules\@eventstore\db-client\dist\streams\utils\ReadStream.js:50:32)
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I am not sure what you have in your database, but I quickly copied the samples code and it works as expected

const {EventStoreDBClient, FORWARDS, StreamNotFoundError, START} = require("@eventstore/db-client");

async function main() {
    const CLOUD_ID = "ca1loplo0aepjgt215o0";
    const client   = EventStoreDBClient.connectionString`esdb+discover://${CLOUD_ID}.mesdb.eventstore.cloud`;

    const events = client.readStream("doesntexist", {
        direction:    FORWARDS,
        fromRevision: START,
        maxCount:     20,
    });

    try {
        for await (const resolvedEvent of events) {
            console.log(resolvedEvent.event?.data);
        }
    } catch (error) {
        if (error instanceof StreamNotFoundError) {
            console.log("Stream not found");
            return;
        }

        throw error;
    }
}

main().then(() => console.log("done"));

When I run it I get:

Stream not found
done
about 4 years ago · Juan Pablo Isaza Report

0

The issue here seems to be that you're trying to check if the stream exists after it's already finished being called.

It may be helpful to move the client.readStream() inside the try/catch, await that directly, then loop over as needed. This at least narrows the point at which it's going wrong, and fails before the for loop is begun.

try {
// Moved down into try block!
  const events = await client.readStream("user", {
    direction: FORWARDS,
    fromRevision: BigInt(10),
    maxCount: 20,
  });

  for (const resolvedEvent of events) {
    console.log(resolvedEvent.event?.data);
  }
  ...
} catch (error) {...}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!