Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda