Prefixing common errors — e.g. under the same package — can be a good way to namespace them. E.g. All codec-related errors start with SOLANA_ERROR__CODECS__.
Use consistent names — e.g. choose PDA or PROGRAM_DERIVED_ADDRESS and stick with it. Ensure your names are consistent with existing error codes. The decision might have been made for you.
Recommended prefixes and suffixes:
MALFORMED_: Some input was not constructed properly. E.g. MALFORMED_BASE58_ENCODED_ADDRESS.
INVALID_: Some input is invalid (other than because it was MALFORMED). E.g. INVALID_NUMBER_OF_BYTES.
EXPECTED_: Some input was different than expected, no need to specify the "GOT" part unless necessary. E.g. EXPECTED_DECODED_ACCOUNT.
_CANNOT_: Some operation cannot be performed or some input cannot be used due to some condition. E.g. CANNOT_DECODE_EMPTY_BYTE_ARRAY or PDA_CANNOT_END_WITH_PDA_MARKER.
_MUST_BE_: Some condition must be true. E.g. NONCE_TRANSACTION_FIRST_INSTRUCTION_MUST_BE_ADVANCE_NONCE.
_FAILED_TO_: Tried to perform some operation and failed. E.g. FAILED_TO_DECODE_ACCOUNT.
_NOT_FOUND: Some operation lead to not finding something. E.g. ACCOUNT_NOT_FOUND.
_OUT_OF_RANGE: Some value is out of range. E.g. ENUM_DISCRIMINATOR_OUT_OF_RANGE.
_EXCEEDED: Some limit was exceeded. E.g. PDA_MAX_SEED_LENGTH_EXCEEDED.
_MISMATCH: Some elements do not match. E.g. ENCODER_DECODER_FIXED_SIZE_MISMATCH.
_MISSING: Some required input is missing. E.g. TRANSACTION_FEE_PAYER_MISSING.
_UNIMPLEMENTED: Some required component is not available in the environment. E.g. SUBTLE_CRYPTO_VERIFY_FUNCTION_UNIMPLEMENTED.
To add a new error, follow the instructions at https://github.com/solana-labs/solana-web3.js/tree/master/packages/errors/#adding-a-new-error
WARNING:
Good naming conventions:
SOLANA_ERROR__CODECS__.PDAorPROGRAM_DERIVED_ADDRESSand stick with it. Ensure your names are consistent with existing error codes. The decision might have been made for you.MALFORMED_: Some input was not constructed properly. E.g.MALFORMED_BASE58_ENCODED_ADDRESS.INVALID_: Some input is invalid (other than because it was MALFORMED). E.g.INVALID_NUMBER_OF_BYTES.EXPECTED_: Some input was different than expected, no need to specify the "GOT" part unless necessary. E.g.EXPECTED_DECODED_ACCOUNT._CANNOT_: Some operation cannot be performed or some input cannot be used due to some condition. E.g.CANNOT_DECODE_EMPTY_BYTE_ARRAYorPDA_CANNOT_END_WITH_PDA_MARKER._MUST_BE_: Some condition must be true. E.g.NONCE_TRANSACTION_FIRST_INSTRUCTION_MUST_BE_ADVANCE_NONCE._FAILED_TO_: Tried to perform some operation and failed. E.g.FAILED_TO_DECODE_ACCOUNT._NOT_FOUND: Some operation lead to not finding something. E.g.ACCOUNT_NOT_FOUND._OUT_OF_RANGE: Some value is out of range. E.g.ENUM_DISCRIMINATOR_OUT_OF_RANGE._EXCEEDED: Some limit was exceeded. E.g.PDA_MAX_SEED_LENGTH_EXCEEDED._MISMATCH: Some elements do not match. E.g.ENCODER_DECODER_FIXED_SIZE_MISMATCH._MISSING: Some required input is missing. E.g.TRANSACTION_FEE_PAYER_MISSING._UNIMPLEMENTED: Some required component is not available in the environment. E.g.SUBTLE_CRYPTO_VERIFY_FUNCTION_UNIMPLEMENTED.