Unverified Commit 551b80ab authored by kladko's avatar kladko

SKALE-3654-better-errors

parent 0b6294b6
......@@ -92,7 +92,7 @@ string convertHexToDec(const string &hex_str) {
throw SGXException(INCORRECT_STRING_CONVERSION, e.what());
} catch (...) {
mpz_clear(dec);
throw SGXException(UNKNOWN_ERROR, "");
throw SGXException(EXCEPTION_IN_CONVERT_HEX_TO_DEC, "Exception in convert hex to dec");
}
clean:
......@@ -117,10 +117,10 @@ string convertG2ToString(const libff::alt_bn128_G2 &elem, int base, const string
return result;
} catch (exception &e) {
throw SGXException(INCORRECT_STRING_CONVERSION, e.what());
throw SGXException(CONVERT_G2_INCORRECT_STRING_CONVERSION, e.what());
return result;
} catch (...) {
throw SGXException(UNKNOWN_ERROR, "");
throw SGXException(EXCEPTION_IN_CONVERT_G2_STRING, "Exception in convert G2 to string");
return result;
}
......@@ -236,7 +236,6 @@ getSecretShares(const string &_polyName, const char *_encryptedPolyHex, const ve
throw SGXException(INVALID_HEX, "Invalid encryptedPolyHex");
}
sgx_status_t status = SGX_SUCCESS;
READ_LOCK(sgxInitMutex);
......@@ -295,10 +294,9 @@ string getSecretSharesV2(const string& _polyName, const char* _encryptedPolyHex,
if (!hex2carray(_encryptedPolyHex, &encLen, encrDKGPoly.data(), BUF_LEN)) {
throw SGXException(INVALID_HEX, "Invalid encryptedPolyHex");
throw SGXException(GET_SS_V2_INVALID_HEX, "Invalid encrypted poly Hex");
}
sgx_status_t status = SGX_SUCCESS;
READ_LOCK(sgxInitMutex);
......
/*
*
Copyright (C) 2019-Present SKALE Labs
This file is part of sgxwallet.
......@@ -83,26 +84,32 @@ spdlog::info(string(__FUNCTION__) + " processed " + to_string(__COUNT__) + " re
}
// if uknown error, the error is 10000 + line number
#define INIT_RESULT(__RESULT__) Json::Value __RESULT__; \
int errStatus = UNKNOWN_ERROR; boost::ignore_unused(errStatus); string errMsg(BUF_LEN, '\0');__RESULT__["status"] = UNKNOWN_ERROR; __RESULT__["errorMessage"] = \
"Server error. Please see server log.";
int errStatus = -1 * (10000 + __LINE__); boost::ignore_unused(errStatus); string errMsg(BUF_LEN, '\0');__RESULT__["status"] = -1 * (10000 + __LINE__); __RESULT__["errorMessage"] = \
string(__FUNCTION__); \
string(__FUNCTION__) + ": server error. Please see server log.";
#define HANDLE_SGX_EXCEPTION(__RESULT__) \
catch (SGXException& _e) { \
if (_e.status != 0) {__RESULT__["status"] = _e.status;} else { __RESULT__["status"] = UNKNOWN_ERROR;}; \
__RESULT__["errorMessage"] = _e.errString; \
catch (const SGXException& _e) { \
if (_e.status != 0) {__RESULT__["status"] = _e.status;} else { __RESULT__["status"] = -1 * (10000 + __LINE__);}; \
__RESULT__["errorMessage"] = _e.errString; \
if (_e.errString.size() == 0) {__RESULT__["errorMessage"] = string(__FUNCTION__);}; \
spdlog::error("JSON call failed {}", __FUNCTION__); \
return __RESULT__; \
} catch (exception& _e) { \
__RESULT__["errorMessage"] = _e.what(); \
} catch (const exception& _e) { \
__RESULT__["status"] = -1 * (10000 + __LINE__); \
exception_ptr p = current_exception(); \
__RESULT__["errorMessage"] = string(p.__cxa_exception_type()->name()) + ":" + _e.what(); \
spdlog::error("JSON call failed {}", __FUNCTION__); \
return __RESULT__; \
}\
catch (...) { \
exception_ptr p = current_exception(); \
printf("Exception %s \n", p.__cxa_exception_type()->name()); \
__RESULT__["errorMessage"] = "Unknown exception"; \
spdlog::error(string("Exception:") + p.__cxa_exception_type()->name()); \
__RESULT__["errorMessage"] = string(p.__cxa_exception_type()->name()); \
spdlog::error("JSON call failed {}", __FUNCTION__); \
return __RESULT__; \
}
......
This diff is collapsed.
......@@ -67,7 +67,7 @@ extern bool autoconfirm;
#define ECDSA_ENCR_LEN 93
#define ECDSA_BIN_LEN 33
#define UNKNOWN_ERROR -1
#define PLAINTEXT_KEY_TOO_LONG -2
#define UNPADDED_KEY -3
#define NULL_KEY -4
......@@ -88,14 +88,69 @@ extern bool autoconfirm;
#define INVALID_ECDSA_KEY_NAME -20
#define INVALID_HEX -21
#define INVALID_ECSDA_SIGNATURE -22
#define KEY_NAME_ALREADY_EXISTS -23 \
#define INVALID_ECSDA_SIGNATURE -22
#define KEY_NAME_ALREADY_EXISTS -23
#define EMPTY_ENCRYPTED_KEY_SHARE -24
#define INVALID_BLS_KEY_SHARE -25
#define INVALID_BLS_HEX -26
#define INVALID_ECDSA_HEX -27
#define COULD_NOT_BLS_SIGN -28
#define INVALID_ECDSA_IMPORT_KEY_NAME -29
#define INVALID_ECDSA_IMPORT_HEX -30
#define ECDSA_GEN_EMPTY_KEY -31
#define INVALID_ECDSA_SIGN_KEY_NAME -32
#define ERROR_IN_ENCLAVE -33
#define INVALID_ECDSA_SIGN_HASH -34
#define INVALID_ECDSA_SIGN_BASE -35
#define INVALID_ECSDA_SIGN_SIGNATURE -36
#define INVALID_ECDSA_GETPKEY_KEY_NAME -37
#define INVALID_GEN_DKG_POLY_NAME -38
#define INVALID_GEN_DKG_PARAM_T -39
#define INVALID_VERIFY_DKG_PARAM_T -40
#define INVALID_DKG_GETVV_POLY_NAME -41
#define INVALID_DKG_GETVV_PARAMS -42
#define INVALID_DKG_GETSS_POLY_NAME -43
#define FILE_NOT_FOUND -44
#define INVALID_DKG_GETSS_PARAMS -45
#define INVALID_DKG_GETSS_PUB_KEY_COUNT -46
#define INVALID_DKG_GETSS_KEY_HEX -47
#define INVALID_DKG_VERIFY_ECDSA_KEY_NAME -48
#define INVALID_DKG_VERIFY_PARAMS -49
#define INVALID_DKG_VERIFY_SS_HEX -50
#define INVALID_DKG_VERIFY_PUBSHARES_LENGTH -51
#define INVALID_CREATE_BLS_KEY_SECRET_SHARES_LENGTH -52
#define INVALID_CREATE_BLS_ECDSA_KEY_NAME -53
#define INVALID_CREATE_BLS_POLY_NAME -54
#define FAIL_TO_CREATE_CERTIFICATE -55
#define INVALID_CREATE_BLS_KEY_NAME -56
#define INVALID_CREATE_BLS_DKG_PARAMS -57
#define INVALID_CREATE_BLS_SHARE -58
#define INVALID_GET_BLS_PUBKEY_NAME -59
#define INVALID_DKG_CALCULATE_ALL_PARAMS -60
#define INVALID_DKG_CALCULATE_ALL_PUBSHARES -61
#define INVALID_DKG_CALCULATE_ALL_PUBSHARES_SIZE -62
#define INVALID_DKG_CALCULATE_ALL_PUBSHARES_STRING -63
#define INVALID_DKG_CALCULATE_ALL_STRING_PUBSHARES_SLENGTH -64
#define INVALID_DKG_CALCULATE_ALL_STRING_PUBKEYS_SIZE -65
#define INVALID_COMPLAINT_RESPONSE_POLY_NAME -66
#define INVALID_DKG_GETSS_V2_PARAMS -63
#define INVALID_DKG_GETSS_V2_POLY_NAME -64
#define INVALID_DKG_GETSS_V2_PUBKEY_COUNT -65
#define INVALID_DKG_GETSS_V2_PUBKEY_HEX -66
#define INVALID_DKG_VV_V2_ECDSA_KEY_NAME -67
#define INVALID_DKG_VV_V2_PARAMS -68
#define INVALID_DKG_VV_V2_SS_HEX -69
#define INVALID_DKG_VV_V2_SS_COUNT -70
#define EXCEPTION_IN_CONVERT_HEX_TO_DEC -71
#define GET_SS_V2_INVALID_HEX -72
#define EXCEPTION_IN_CONVERT_G2_STRING -73
#define CONVERT_G2_INCORRECT_STRING_CONVERSION -74
#define SGX_ENCLAVE_ERROR -666
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment