LiskArchive / lisk-sdk

🔩 Lisk software development kit
https://lisk.com
Apache License 2.0
2.72k stars 456 forks source link

Update validation error object matching Ajv ErrorObject #6332

Closed nazarhussain closed 11 months ago

nazarhussain commented 3 years ago

Description

While upgrading Ajv to version 8.1.0. Its observed that ErrorObject introduced a couple of changes. To keep the backend compatibility we introduced a wrapper to covert the error object.

https://github.com/LiskHQ/lisk-sdk/blob/c632e17a24e1a865fa6a14cb2147d24634e52f24/elements/lisk-validator/src/types.ts#L19-L22

https://github.com/LiskHQ/lisk-sdk/blob/c632e17a24e1a865fa6a14cb2147d24634e52f24/elements/lisk-validator/src/errors.ts#L40

We also have our own implementation of ErrorObject to single string conversion.

https://github.com/LiskHQ/lisk-sdk/blob/c632e17a24e1a865fa6a14cb2147d24634e52f24/elements/lisk-validator/src/errors.ts#L54

The Ajv in version 8.1.0 introduced ajv.errorText(errors) for the same purpose. We should move our implementation to this native function.

Motivation

The above mentioned changes will provide us following benefits;

  1. Use consistent error object structure while debugging
  2. Stay aligned with the validation library we are using
  3. Easy to use third party libraries around ajv without any compatibility issues
  4. We may in future start using ajv-errors to specify custom error messages inside schema declaration
  5. We can also use ajv-i18n for internationlization of error messages

Acceptance Criteria

Additional Information

shuse2 commented 11 months ago

Closing this issue for no activity