Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda