From 9a965852db50cb53dcbc717e626f5b98edef7cc2 Mon Sep 17 00:00:00 2001 From: neithanmo Date: Thu, 9 Jan 2025 07:40:19 -0600 Subject: [PATCH] Normalice error definitions --- app/rust/src/parser/error.rs | 13 +++- app/src/common/parser_common.h | 50 ++++++-------- app/src/parser_impl.c | 122 +++++++++++++++++++-------------- 3 files changed, 100 insertions(+), 85 deletions(-) diff --git a/app/rust/src/parser/error.rs b/app/rust/src/parser/error.rs index c6dda98..7c2732a 100644 --- a/app/rust/src/parser/error.rs +++ b/app/rust/src/parser/error.rs @@ -21,23 +21,28 @@ use nom::error::ErrorKind; #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum ParserError { Ok = 0, + // Generic errors NoData, InitContextEmpty, DisplayIdxOutOfRange, DisplayPageOutOfRange, UnexpectedError, + // Method/Version related UnexpectedMethod, UnexpectedVersion, UnexpectedCharacters, + // Field related DuplicatedField, MissingField, UnexpectedField, + // Transaction related UnknownTransaction, InvalidTransactionType, + // Plan related SpendPlanError, OutputPlanError, @@ -48,10 +53,12 @@ pub enum ParserError { ParameterHashError, EffectHashError, UndelegateClaimPlanError, + // Chain related InvalidChainId, UnexpectedChain, - // Other existing variants + + // Cryptographic and key-related errors InvalidHashMode, InvalidSignature, InvalidPubkeyEncoding, @@ -86,13 +93,13 @@ pub enum ParserError { PrecisionTooLarge, ClueCreationFailed, InvalidAssetId, - // Additional variants from C enum DetectionDataOverflow, ActionsOverflow, InvalidMetadata, + InvalidSignatureLen, Overflow, NonIntegral, - InvalidSignatureLen, // Added from C enum + UnexpectedValue, } impl From for ParserError { diff --git a/app/src/common/parser_common.h b/app/src/common/parser_common.h index d6e6b76..0c4aff4 100644 --- a/app/src/common/parser_common.h +++ b/app/src/common/parser_common.h @@ -83,17 +83,9 @@ typedef enum { // Cryptographic and key-related errors parser_invalid_hash_mode, parser_invalid_signature, - parser_invalid_signature_len, parser_invalid_pubkey_encoding, - parser_invalid_clue_key, - parser_invalid_tx_key, - parser_invalid_fq, - parser_invalid_detection_key, - parser_invalid_fvk, - parser_invalid_ivk, - parser_invalid_key_len, - - // Data validation errors + parser_invalid_address_version, + parser_invalid_address_length, parser_invalid_type_id, parser_invalid_codec, parser_invalid_threshold, @@ -101,35 +93,35 @@ typedef enum { parser_invalid_ascii_value, parser_invalid_timestamp, parser_invalid_staking_amount, + parser_unexpected_type, + parser_operation_overflows, + parser_unexpected_buffer_end, + parser_unexpected_number_items, + parser_value_out_of_range, parser_invalid_address, - parser_invalid_address_version, - parser_invalid_address_length, parser_invalid_path, parser_invalid_length, - parser_invalid_precision, - parser_invalid_metadata, + parser_too_many_outputs, + parser_unexpected_data, + parser_invalid_clue_key, + parser_invalid_tx_key, + parser_invalid_fq, + parser_invalid_detection_key, + parser_invalid_fvk, + parser_invalid_ivk, + parser_invalid_key_len, parser_invalid_action_type, + parser_invalid_precision, + parser_precision_too_large, + parser_clue_creation_failed, parser_invalid_asset_id, - - // Overflow and limit errors - parser_operation_overflows, parser_detection_data_overflow, parser_actions_overflow, - parser_too_many_outputs, - parser_precision_too_large, + parser_invalid_metadata, + parser_invalid_signature_len, parser_overflow, parser_non_integral, - - // Buffer and data errors - parser_unexpected_buffer_end, parser_unexpected_value, - parser_unexpected_number_items, - parser_unexpected_type, - parser_unexpected_data, - parser_value_out_of_range, - - // Other errors - parser_clue_creation_failed, } parser_error_t; typedef struct { diff --git a/app/src/parser_impl.c b/app/src/parser_impl.c index a892047..bfb06ae 100644 --- a/app/src/parser_impl.c +++ b/app/src/parser_impl.c @@ -201,8 +201,11 @@ parser_error_t _read(parser_context_t *c, parser_tx_t *v) { const char *parser_getErrorDescription(parser_error_t err) { switch (err) { + // Success case parser_ok: return "No error"; + + // Generic errors case parser_no_data: return "No more data"; case parser_init_context_empty: @@ -213,6 +216,56 @@ const char *parser_getErrorDescription(parser_error_t err) { return "Display page out of range"; case parser_unexpected_error: return "Unexpected error"; + + // Method/Version related + case parser_unexpected_method: + return "Unexpected method"; + case parser_unexpected_version: + return "Unexpected version"; + case parser_unexpected_characters: + return "Unexpected characters"; + + // Field related + case parser_duplicated_field: + return "Unexpected duplicated field"; + case parser_missing_field: + return "Missing field"; + case parser_unexpected_field: + return "Unexpected field"; + + // Transaction related + case parser_unknown_transaction: + return "Unknown transaction"; + case parser_invalid_transaction_type: + return "Invalid transaction type"; + + // Plan related + case parser_spend_plan_error: + return "Spend plan error"; + case parser_output_plan_error: + return "Output plan error"; + case parser_delegate_plan_error: + return "Delegate plan error"; + case parser_undelegate_plan_error: + return "Undelegate plan error"; + case parser_ics20_withdrawal_plan_error: + return "ICS20 withdrawal plan error"; + case parser_swap_plan_error: + return "Swap plan error"; + case parser_parameter_hash_error: + return "Parameter hash error"; + case parser_effect_hash_error: + return "Effect hash error"; + case parser_undelegate_claim_plan_error: + return "Undelegate claim plan error"; + + // Chain related + case parser_invalid_chain_id: + return "Invalid chain ID"; + case parser_unexpected_chain: + return "Unexpected chain"; + + // Cryptographic and key-related errors case parser_invalid_hash_mode: return "Invalid hash mode"; case parser_invalid_signature: @@ -231,16 +284,24 @@ const char *parser_getErrorDescription(parser_error_t err) { return "Invalid threshold"; case parser_invalid_network_id: return "Invalid network ID"; - case parser_invalid_chain_id: - return "Invalid chain ID"; case parser_invalid_ascii_value: return "Invalid ASCII value"; case parser_invalid_timestamp: return "Invalid timestamp"; case parser_invalid_staking_amount: return "Invalid staking amount"; + case parser_unexpected_type: + return "Unexpected type"; case parser_operation_overflows: return "Operation overflows"; + case parser_unexpected_buffer_end: + return "Unexpected buffer end"; + case parser_unexpected_number_items: + return "Unexpected number of items"; + case parser_value_out_of_range: + return "Value out of range"; + case parser_invalid_address: + return "Invalid address"; case parser_invalid_path: return "Invalid path"; case parser_invalid_length: @@ -273,66 +334,21 @@ const char *parser_getErrorDescription(parser_error_t err) { return "Clue creation failed"; case parser_invalid_asset_id: return "Invalid asset ID"; - case parser_unexpected_type: - return "Unexpected type"; - case parser_unexpected_method: - return "Unexpected method"; - case parser_unexpected_buffer_end: - return "Unexpected buffer end"; - case parser_unexpected_value: - return "Unexpected value"; - case parser_unexpected_number_items: - return "Unexpected number of items"; - case parser_unexpected_version: - return "Unexpected version"; - case parser_unexpected_characters: - return "Unexpected characters"; - case parser_unexpected_field: - return "Unexpected field"; - case parser_duplicated_field: - return "Unexpected duplicated field"; - case parser_value_out_of_range: - return "Value out of range"; - case parser_invalid_address: - return "Invalid address"; - case parser_unexpected_chain: - return "Unexpected chain"; - case parser_missing_field: - return "Missing field"; - case parser_unknown_transaction: // Fixed typo in enum name - return "Unknown transaction"; - case parser_invalid_transaction_type: // Added - return "Invalid transaction type"; case parser_detection_data_overflow: return "Detection data overflow"; case parser_actions_overflow: return "Actions overflow"; - case parser_spend_plan_error: - return "Spend plan error"; - case parser_output_plan_error: - return "Output plan error"; - case parser_delegate_plan_error: - return "Delegate plan error"; - case parser_undelegate_plan_error: - return "Undelegate plan error"; - case parser_ics20_withdrawal_plan_error: - return "ICS20 withdrawal plan error"; - case parser_swap_plan_error: - return "Swap plan error"; - case parser_parameter_hash_error: // Added - return "Parameter hash error"; - case parser_effect_hash_error: // Added - return "Effect hash error"; - case parser_undelegate_claim_plan_error: // Added - return "Undelegate claim plan error"; case parser_invalid_metadata: return "Invalid metadata"; - case parser_invalid_signature_len: // Added to match enum + case parser_invalid_signature_len: return "Invalid signature length"; - case parser_overflow: // Added + case parser_overflow: return "Overflow error"; - case parser_non_integral: // Added + case parser_non_integral: return "Non-integral value error"; + case parser_unexpected_value: + return "Unexpected value"; + default: return "Unrecognized error code"; }