Optimal Placement for `Effect.runPromise` in Supabase Insert Operations

Where is the best place to execute Effect.runPromise and its counterparts? I assume higher up in the chain is better, but I am just having a hard time finding a good spot to put it (lately I've just been putting it inside of the function that holds my effects, which I assume is an anti-pattern). For reference, this is what I have been doing (on an insert call for my Supabase db):

export const insertIntoTable = async ({
    client,
    data,
    tableName,
}: InsertArgs) =>
    Effect.runPromise(
        Effect.tryPromise(async () => {
            const resp = await client.from(tableName).insert(data);

            if (resp.error) {
                console.error(
                    `An error occurred while inserting a table entry:`,
                    resp.error
                );
                // Also as a side note, where does Effect.fail usually propogate to? For me in this scenario it seems like the errors just never appear, but I'm sure it's user error on my part
                return Effect.fail(resp.error);
            } else {
                return Effect.succeed(resp.data);
            }
        })
    );
Was this page helpful?