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(common): preconditions utility with coded errors #266

Closed
petermetz opened this issue Aug 27, 2020 · 0 comments · Fixed by #275
Closed

feat(common): preconditions utility with coded errors #266

petermetz opened this issue Aug 27, 2020 · 0 comments · Fixed by #275
Assignees
Labels

Comments

@petermetz
Copy link
Member

Description

As a developer I want to have an easier way to assert truthy-ness of values so that I'm more productive in general and less likely to omit/forget crucial validation of method input parameters for example.

There's a lot of "manual" validation in the code as of right now and it would be nice to have something instead that is similar to Guava's Preconditions class just for Typescript so that we can replace these

    const fnTag = "DeployContractGoBinEndpointV1#constructor()";
    if (!options) {
      throw new Error(`${fnTag} options falsy.`);
    }
    if (!options.path) {
      throw new Error(`${fnTag} options.path falsy.`);
    }

with the much more concise version like this:

    const fnTag = "DeployContractGoBinEndpointV1#constructor()";
    Checks.truthy(options, `${fnTag} options`);
    Checks.truthy(options.path, `${fnTag} options.path`);

Acceptance Criteria

  1. Create a class called Checks and another one called CodedError
  2. Checks can do general assertions for truthy-ness and throw CodedError instances which are extended from the standard Error but add a code property which can make it easy to detect and equality compare two CodedError classes even if their message property varies because it has something in it that is a variable (like an ID of a transaction block or whatever else that's not static strings)
  3. Both of these classes must work in the browser and have test coverage.

cc: @sfuji822 @takeutak @jonathan-m-hamilton

@petermetz petermetz self-assigned this Aug 27, 2020
petermetz added a commit to petermetz/cacti that referenced this issue Sep 5, 2020
Utilities for easier one-liners that can verify arguments or
execution state in a much more concise way compared to
if conditions throwing manually. Makes the code less verbose
and requires less typing as well.

Also: added a bools utlity class for checking strict boolean
typing of a value and a new string utility method as well.

Fixes hyperledger#266

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
petermetz added a commit that referenced this issue Sep 11, 2020
Utilities for easier one-liners that can verify arguments or
execution state in a much more concise way compared to
if conditions throwing manually. Makes the code less verbose
and requires less typing as well.

Also: added a bools utlity class for checking strict boolean
typing of a value and a new string utility method as well.

Fixes #266

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant