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.
Anything that throws an error when something is not valid has been renamed to requireFoo
Functions that do simple type checking without validating contents should end with Type
If an attachment has multiple URLs, only one need be valid. The following examples would be valid:
One url has only unsupported hash algorithms - MD5 + secp256k1, but the other has keccak256 which is supported.
One url href is ftp but the other is https
If a Note or Profile has multiple attachments, only one need be valid. The following examples would be valid:
Two image attachments: one has only a url pointing to a HEIC (unsupported) and the other points to a JPEG (supported)
Two image attachments: one points to an FTP URL (unsupported) and the other is an HTTPS URL (supported).
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.
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.
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:
[x] Did you update the changelog?
[x] Any new modules need to be exported? NO
[x] Are new methods in the right module?
[x] N/AAre new methods/modules in core or not (i.e. porcelain or plumbing)?
[x] Do you have good documentation on exported methods?
Change summary:
Rework and rename validators to throw or log informative errors when an ActivityContent is invalid
Redo tests to reflect changes, add more to improve test coverage
Fix a bug in DURATION_REGEX
Steps to Verify:
Please help by reviewing for consistent naming.
All tests should pass -- see test coverage
There are tests for as many potential error cases (modulo being in different attachments), so if you think of one I've left out please comment.
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.
requireFoo
Type
ftp
but the other ishttps
InvalidActivityContentError
sayingActivityContentLink href is invalid
.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.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:
ActivityContent
is invalidDURATION_REGEX
Steps to Verify: