Proposal for a More Ergonomic Error Handling Approach Using `catchTags` in Effect Typescript

After some discussion with @attila about a more ergonomic way of handling the rest of the errors,
for instance:
    yield* s3.headObject({ Bucket: config.bucketName, Key: path }).pipe(
      Effect.catchTag("NotFound", (err) =>
        Effect.fail(
          SystemError({module: "FileSystem", method: "access", reason: "NotFound", message: err.message, pathOrDescriptor: path }),
        )),
      Effect.catchAll((err) =>
        Effect.fail(
          SystemError({module: "FileSystem", method: "access", reason: "Unknown", message: err.message, pathOrDescriptor: path }),
        )
      ),
    );

currently obviously catchAll recatch the error above

of course I can use custom function where I can check _tag and conditionally return what I need.

but would it be feasable having more functional approach like
yield* s3.headObject({ Bucket: config.bucketName, Key: path }).pipe(
  Effect.catchTags(
    // specific error handlers
    {
      NotFound: () => (err) =>
        Effect.fail(
          SystemError({module: "FileSystem", method: "access", reason: "NotFound", message: err.message, pathOrDescriptor: path }),
        ),
    },
    // rest handler (optional param)
    (error) => 
        Effect.fail(
          SystemError({module: "FileSystem", method: "access", reason: "Unknown", message: err.message, pathOrDescriptor: path }),
        )
  ),
);

where catchTags would have an overload accepting function handling rest of errors.

or having smth like catchAllRest

please advice if there is another way doing it...
Was this page helpful?