Skip to content

SDK Error types (ResourceNotFoundError etc) should be exposed as constructable values to allow for unit test mocks #110

@dmeehan1968

Description

@dmeehan1968

Errors are exposed only as types, which means that its not easy to create mocks for the AWS services. Example for jest/jest-mock-extended:

    this.scheduler = mock<Context.Tag.Service<SchedulerService>>()

    this.scheduler.updateSchedule.mockReturnValue(
      Effect.fail({
        ...new ResourceNotFoundException({
          message: 'not found',
          Message: 'Not Found',
          $metadata: {},
        }),
        _tag: 'ResourceNotFoundException',
      }),
    )

Usability could be vastly improved by providing a constructor for the error, with some possible optimisation to provide sensible defaults, eg.:

this.scheduler.updateSchedule.mockReturnValue(
  Effect.fail(new ResourceNotFoundError({ Message: 'Not Found' }))
)

One could apply a kludge such as:

this.scheduler.updateSchedule.mockReturnValue(
      Effect.fail({
        _tag: 'ResourceNotFoundException',
      } as ResourceNotFoundError),
)

although possibly ugly and error prone should the effect-aws library change the constants.

Different mock frameworks will have their own behaviours, but at a fundamental level, the ability to more readily construct error types would be useful.

As an aside, the service type could be exported within the service namespace, so we can avoid the Context.Tag.Service<xxx> and have something like Service.Type. I think that effect-aws could improve the exports, to better mirror those used within effect as a whole (Effect.Service exports Default as the primary layer for example).

Metadata

Metadata

Assignees

No one assigned

    Labels

    commonsAnything related to common implementationsenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions