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

feat(packages/sui-decorators): Create AsyncInlineError decorator #1746

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

oriolpuig
Copy link
Contributor

@oriolpuig oriolpuig commented Mar 27, 2024

Description

Frontend Tech Community has agreed to create, use, and standardize the @AsyncInlineError() decorator. It will improve our code readability.

This decorator catch-all method errors and each method instead of return a value, will return a tuple like [error, response]. So, with this decorator a method using it will never fail.

On this PR, we provide:

  • A new @AsyncInlineError() decorator
  • Update the needed documentation
  • New linting rules created to push our ADR decisions.
    • MUST The @AsyncInlineError() must be the first decorator in a method. It will make our life easier when we develop other decorators. The rule provide a quick fix.
    • SHOULD The @AsyncInlineError() should be used in all UseCase.execute, Service.execute and Repository.method. The rule will NOT provide a quick fix to avoid uncontrolled errors.
@AsyncInlineError()
function execute() {
  if(error) {
    throw new Error('this is not ok')
  }
  return 'this is ok'
}

const response = execute()
const [error, result] = response

Related Issue

Example

Client test ✅

image

Server test ✅

image

@oriolpuig oriolpuig marked this pull request as ready for review March 27, 2024 11:19
@marcbenito marcbenito force-pushed the poc/create_new_async_inline_error branch from 4616cab to dc9b3c3 Compare May 29, 2024 08:42
@oriolpuig oriolpuig force-pushed the poc/create_new_async_inline_error branch from 4c839d6 to 6294dd8 Compare July 2, 2024 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants