Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

effect's Cause.UnknownException causes issues #12600

Open
m-radmacher opened this issue Jul 16, 2024 · 2 comments
Open

effect's Cause.UnknownException causes issues #12600

m-radmacher opened this issue Jul 16, 2024 · 2 comments
Labels
bug Something isn't working needs triage

Comments

@m-radmacher
Copy link

What version of Bun is running?

1.1.20+ae1948925

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

Run this script using Bun (you'll need to have the effect@3.5.3 package installed:

import { Config, Console, Effect, Redacted } from "effect";

const getJson = ({ url }: { url: string }) =>
    Effect.tryPromise(() =>
        fetch(url).then((res) => {
            if (!res.ok) {
                console.log("error");
                throw new Error(res.statusText);
            }
            console.log("ok");
            return res.json() as unknown;
        }),
    ).pipe(
        Effect.retry({ times: 2 }),
        Effect.timeout("4 seconds"),
        Effect.catchAll(Console.error),
    );

const program = Effect.gen(function* () {
    const host = "https://dummyjson.com/auth/products/1?delay=1000";

    const unknownResponse = yield* getJson({
        url: host,
    });

  console.log(unknownResponse);
});


Effect.runPromise(program);

What is the expected behavior?

I expected to see an error message and a stack trace.

What do you see instead?

$ bun --watch src/test.ts
error
error
error
[custom formatter threw an exception] <---- this is unexpected
undefined

Additional information

One of the effects members asked me to open this issue to cross-reference. You can find the issue in their repository here: Effect-TS/effect#3270

@m-radmacher m-radmacher added bug Something isn't working needs triage labels Jul 16, 2024
@190n
Copy link
Contributor

190n commented Jul 18, 2024

This is happening because some object has a [util.inspect.custom] function which throws. In Bun, passing such an object to util.inspect will throw the error (which is how it works in Node.js too), but using any console functions (or Bun.inspect, but I don't think effect uses that anywhere) will swallow the error and print the message you're seeing.

Do you have a smaller reproduction that doesn't use effect, or could you point me to the part of effect that is creating/logging this object?

@m-radmacher
Copy link
Author

I do have a smaller reproduction:

console.error(new Cause.UnknownException(new Error("Foo")))

It also seems that my issue was closed as completed in the effect repository with this PR: Effect-TS/effect#3295

But since that hasn't been released on npm yet, I haven't tried it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants