Understanding Effect.try Return Types in Programming

Hey guys! Does Effect.try returns a different type when it succeed than other utils? Could somebody explain what's going on here? 😅

Code is coming...

// I have the following util:
export function safeJsonParse(
  value: string,
  errorMessage: string = 'Something went wrong during JSON data parsing',
): Effect.Effect<unknown, JsonParseError, never> {
  return Effect.try({
    try: () => JSON.parse(value),
    catch: () => new JsonParseError({ message: errorMessage }),
  })
}

// I am trying to write some simple unit tests (I am using vitest)
expect(safeJsonParse('"duck"')).toStrictEqual(Effect.succeed('duck'))
expect(safeJsonParse('null')).toStrictEqual(Effect.succeed(null))
expect(safeJsonParse('undefined')).toStrictEqual(Effect.succeed(undefined))


I have used the syntax above for other utils I wrote using
Effect
and there was no issue when I was running the tests.
Now these cases fail but if I would change it to this:
expect(safeJsonParse('"duck"').pipe(Effect.runSyncExit)).toStrictEqual(Effect.succeed('duck'))

It is all good. I am a bit puzzled here 😵‍💫
Was this page helpful?