Skip to content

Commit

Permalink
#122 add exception for public_key not selected case
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-modelist-dev committed Feb 14, 2019
1 parent f17a1d4 commit 908f85f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions keychain_lib/include/keychain_lib/keychain_commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ struct keychain_command<command_te::select_key>: keychain_command_base
virtual std::string operator()(keychain_base* keychain, const fc_light::variant& params_variant, int id) const override
{
auto public_key = *keychain->select_key();
if(!public_key)
FC_LIGHT_THROW_EXCEPTION(fc_light::public_key_not_selected, "");
json_response response(to_hex(public_key.data(), public_key.size).c_str(), id);
return fc_light::json::to_string(fc_light::variant(response));
}
Expand Down
14 changes: 11 additions & 3 deletions libraries/fc_light/include/fc_light/exception/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace fc_light
privkey_not_found_code , ///< private key not found by public key
privkey_invalid_unlock_code , ///< cannot unlock private key, possible wrong password
password_input_error_code , ///< error while getting password
public_key_not_selected_code , ///< public_key has not been selected by user
operation_canceled_code , ///< operation has been canceled by user
internal_error_code , ///< some unspecified internal error

//internal errors
Expand All @@ -41,7 +43,7 @@ namespace fc_light
divide_by_zero_code ,
out_of_range_exception_code ,
eof_exception_code ,
operation_canceled_code ,


//3d party exceptions
std_exception_code , ///< for std::exceptions (3rd party)
Expand Down Expand Up @@ -289,6 +291,12 @@ namespace fc_light
* @brief command not implemented
*/
FC_LIGHT_DECLARE_EXCEPTION( command_depreciated, command_depreciated_code, "Command depreciated" );

/**
* @brief user decline actions
*/
FC_LIGHT_DECLARE_EXCEPTION( public_key_not_selected, public_key_not_selected_code, "Public key not selected")
FC_LIGHT_DECLARE_EXCEPTION( operation_canceled, operation_canceled_code, "Operation canceled by user")

/**
* @brief get password error
Expand Down Expand Up @@ -324,7 +332,6 @@ namespace fc_light
*/
FC_LIGHT_DECLARE_EXCEPTION( assert_exception, assert_exception_code, "Assert exception" );
FC_LIGHT_DECLARE_EXCEPTION( eof_exception, eof_exception_code, "End of file" );
FC_LIGHT_DECLARE_EXCEPTION( operation_canceled, operation_canceled_code, "Operation canceled by user")
FC_LIGHT_DECLARE_EXCEPTION( null_optional, null_optional_code, "Null optional" );
FC_LIGHT_DECLARE_EXCEPTION( encryption_exception, encryption_error_code, "Encryption error" );
FC_LIGHT_DECLARE_EXCEPTION( internal_error_exception, internal_error_code, "Internal error" );
Expand Down Expand Up @@ -537,6 +544,8 @@ FC_LIGHT_REFLECT_ENUM(
(privkey_not_found_code)
(privkey_invalid_unlock_code)
(password_input_error_code)
(public_key_not_selected_code)
(operation_canceled_code)
(internal_error_code)

(parse_error_exception_code)
Expand All @@ -552,7 +561,6 @@ FC_LIGHT_REFLECT_ENUM(
(divide_by_zero_code)
(out_of_range_exception_code)
(eof_exception_code)
(operation_canceled_code)

(std_exception_code)
(unhandled_exception_code))

0 comments on commit 908f85f

Please sign in to comment.