mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #7785 from ethereum/exception-cleanup
A lot of tiny cleanups to exceptions
This commit is contained in:
@@ -87,7 +87,7 @@ int dev::fromHex(char _i, WhenError _throw)
|
||||
if (_i >= 'A' && _i <= 'F')
|
||||
return _i - 'A' + 10;
|
||||
if (_throw == WhenError::Throw)
|
||||
BOOST_THROW_EXCEPTION(BadHexCharacter() << errinfo_invalidSymbol(_i));
|
||||
assertThrow(false, BadHexCharacter, to_string(_i));
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
@@ -100,22 +100,18 @@ bytes dev::fromHex(std::string const& _s, WhenError _throw)
|
||||
|
||||
if (_s.size() % 2)
|
||||
{
|
||||
int h = fromHex(_s[s++], WhenError::DontThrow);
|
||||
int h = fromHex(_s[s++], _throw);
|
||||
if (h != -1)
|
||||
ret.push_back(h);
|
||||
else if (_throw == WhenError::Throw)
|
||||
BOOST_THROW_EXCEPTION(BadHexCharacter());
|
||||
else
|
||||
return bytes();
|
||||
}
|
||||
for (unsigned i = s; i < _s.size(); i += 2)
|
||||
{
|
||||
int h = fromHex(_s[i], WhenError::DontThrow);
|
||||
int l = fromHex(_s[i + 1], WhenError::DontThrow);
|
||||
int h = fromHex(_s[i], _throw);
|
||||
int l = fromHex(_s[i + 1], _throw);
|
||||
if (h != -1 && l != -1)
|
||||
ret.push_back((uint8_t)(h * 16 + l));
|
||||
else if (_throw == WhenError::Throw)
|
||||
BOOST_THROW_EXCEPTION(BadHexCharacter());
|
||||
else
|
||||
return bytes();
|
||||
}
|
||||
|
||||
@@ -51,7 +51,6 @@ DEV_SIMPLE_EXCEPTION(FileError);
|
||||
DEV_SIMPLE_EXCEPTION(DataTooLong);
|
||||
|
||||
// error information to be added to exceptions
|
||||
using errinfo_invalidSymbol = boost::error_info<struct tag_invalidSymbol, char>;
|
||||
using errinfo_comment = boost::error_info<struct tag_comment, std::string>;
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <libdevcore/IpfsHash.h>
|
||||
|
||||
#include <libdevcore/Assertions.h>
|
||||
#include <libdevcore/Exceptions.h>
|
||||
#include <libdevcore/picosha2.h>
|
||||
#include <libdevcore/CommonData.h>
|
||||
@@ -55,11 +56,7 @@ string base58Encode(bytes const& _data)
|
||||
|
||||
bytes dev::ipfsHash(string _data)
|
||||
{
|
||||
if (_data.length() >= 1024 * 256)
|
||||
BOOST_THROW_EXCEPTION(
|
||||
DataTooLong() <<
|
||||
errinfo_comment("Ipfs hash for large (chunked) files not yet implemented.")
|
||||
);
|
||||
assertThrow(_data.length() < 1024 * 256, DataTooLong, "IPFS hash for large (chunked) files not yet implemented.");
|
||||
|
||||
bytes lengthAsVarint = varintEncoding(_data.size());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user