LibertyDSNP / eth-sdk-ts

TypeScript SDK for DSNP on Ethereum
Apache License 2.0
9 stars 1 forks source link

Bugs/better errors #179106793 #132

Closed shannonwells closed 3 years ago

shannonwells commented 3 years ago

Problem

We need more informative errors. Fixes #179106793

Solution

Since the only entry points to the validations threw an error if the ActivityContent(Note|Profile) was invalid, almost everything now throws an error if it doesn't validate, however, sometimes we only need one item of a list to be valid, in particular, attachments. Attachment validation has been abstracted.

  1. Anything that throws an error when something is not valid has been renamed to requireFoo
  2. Functions that do simple type checking without validating contents should end with Type
  3. If an attachment has multiple URLs, only one need be valid. The following examples would be valid:
    1. One url has only unsupported hash algorithms - MD5 + secp256k1, but the other has keccak256 which is supported.
    2. One url href is ftp but the other is https
  4. If a Note or Profile has multiple attachments, only one need be valid. The following examples would be valid:
    1. Two image attachments: one has only a url pointing to a HEIC (unsupported) and the other points to a JPEG (supported)
    2. Two image attachments: one points to an FTP URL (unsupported) and the other is an HTTPS URL (supported).
  5. A Note or Profile can have an empty attachments array and be valid, but if it doesn't, and none are valid, we rerun our validations without catching errors and throw the first one. Example: An Image attachment for a Note has only an FTP url, the validation will throw an InvalidActivityContentError saying ActivityContentLink href is invalid.
  6. The new function that is used above, requireGetSupportedContentAttachments is also exported for use by SDK developers to assist in debugging or simply to get a list of all the attachments valid for DSNP.
  7. In order to do the above, on the first pass, though attachment validations throw errors, they are caught and logged to console, for ease of debugging.

Error/return value behavior isn't 100% consistent; there's too much going on and needs are different depending on the object's depth.

with @rosalinekarr

Double Checks:

Change summary:

Steps to Verify:

shannonwells commented 3 years ago

@acruikshank , @rosalinekarr Please have a look at the Changelog entry and let me know if you think it's sufficient.