Effect CommunityEC
Effect Communityβ€’2mo agoβ€’
6 replies
tiny_g

No Error Logging in Vitest with Effect Pipeline

Hello!

I am trying out some pipelines in my Vitest environment and I have noticed, that I am not getting any errors logged there by default. When the following code snippet fails, I get no output in the console log. Just that the test silently failed:
import { Effect, Option } from "effect"

const anonymousToken = () => {
  return Option.some(JSON.stringify({ name: "My Name" }))
}

const decodeToken = (shouldFail: boolean) => {
  return (token: string) => {
    return Effect.promise((): Promise<{ name: string }> => {
      if (shouldFail) {
        return Promise.reject(new Error('Failed to decode token'));
      }

      return Promise.resolve(JSON.parse(token));
    })    
  }
}

// Code is executed within Vitest. ex: it('...', () => { ... })
(async () => {
  var result = await Effect.runPromise(
    anonymousToken().pipe(
      Effect.flatMap(decodeToken(true)),
      Effect.optionFromOptional
    )
  )

  console.log(result);
})();

Link to playground: https://effect.website/play/#6b1c4a86cd8f

The odd thing that I noticed is that the playground is not silently failing. This leads me to thinking there is probably some environment variable that I need to set, or there might be a bug in the latest version of effect.ts? I'm using the latest 3.19.8 version.


If I suffix it by Effect.runPromise(...).catch(console.error) The error will be logged.
image.png
Was this page helpful?