Skip to content

Commit

Permalink
Normalice error definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
neithanmo committed Jan 9, 2025
1 parent 097a73a commit 9a96585
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 85 deletions.
13 changes: 10 additions & 3 deletions app/rust/src/parser/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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<ErrorKind> for ParserError {
Expand Down
50 changes: 21 additions & 29 deletions app/src/common/parser_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,53 +83,45 @@ 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,
parser_invalid_network_id,
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 {
Expand Down
122 changes: 69 additions & 53 deletions app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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";
}
Expand Down

0 comments on commit 9a96585

Please sign in to comment.