Struggling with Remix Loader and getUserEffect Error Handling

Hello everyone,

I've been racking my brain for a few hours on this issue, but I can't seem to figure it out (pretty sure I've memorized the error handling docs at this point haha)

I've got this getUserEffect which is called as so within this Remix loader:

export class NoUserError {
    readonly _tag = 'NoUserError';
}

const getUserEffect = ({
    request,
}: GetUserEffectArgs): Effect.Effect<
    User | null,
    AuthError | NoUserError | null,
    never
> =>
    pipe(
        Effect.promise(async () => {
            const { supabaseClient } = createSupabaseServerClient(request);
            const {
                data: { user },
                error,
            } = await supabaseClient.auth.getUser();

            // Why is this failure not being caught by the catchAll later in the pipe?
            Effect.fail(new NoUserError());

            if (error) Effect.fail(error);

            if (user === null) {
                Effect.fail(new NoUserError());
                return null;
            } else {
                return user;
            }
        }).pipe(
            Effect.catchAll((err) => {
                // This is never seen in the console
                console.error(`An error occurred while getting a user: ${err}`);
                return Effect.fail(err);
            })
        ),

        // This log works perfectly fine!
        Effect.tap(() => Effect.log('Got the user!'))
    );

export const loader = async ({ request }: LoaderFunctionArgs) => {
    if (process.env.IS_LIVE === 'false') return redirect('/coming-soon');

    const load = Effect.all([getUserEffect({ request })]);

    const [user] = await Effect.runPromise(load);

    if (!user) {
        return redirect('/');
    }

    return json({
        user: user,
    });
};


However, I can't figure out why this (intentionally placed) failure does not seem to be caught. Could I get a quick rundown of why this isn't handled as expected?

Thank you again!!!
Was this page helpful?