effect icon indicating copy to clipboard operation
effect copied to clipboard

Inconsistency between Cause.Fail instance and toJSON

Open Wraul opened this issue 9 months ago • 0 comments

What version of Effect is running?

3.14.1

What steps can reproduce the bug?

import { Cause } from "effect";

const cause = Cause.fail("Error");

console.log(cause);

if (Cause.isFailType(cause)) {
  // console.log(cause.failure); <-- does not type check
  console.log(cause.error);
}

The console.log(cause) prints the following

{ _id: 'Cause', _tag: 'Fail', failure: 'Error' }

Indicating that there should be a failure property on the cause object. But in reality there is none as can be seen in the if statement. There is a error property though.

What is the expected behavior?

I was expecting that what the console.log emitted should correspond to the structure of the cause object.

What do you see instead?

The console.log(cause) indicates that there is a failure property on the cause object, when there in fact is no such property.

Additional information

I believe this are due to the toJSON implementation for the Cause.Fail in effect/src/internal/cause.ts.

Wraul avatar Apr 01 '25 14:04 Wraul