| 116 | } |
| 117 | |
| 118 | Json formatErrorWithException( |
| 119 | CharStreamProvider const& _charStreamProvider, |
| 120 | util::Exception const& _exception, |
| 121 | Error::Type _type, |
| 122 | std::string const& _component, |
| 123 | std::string const& _message, |
| 124 | std::optional<ErrorId> _errorId = std::nullopt |
| 125 | ) |
| 126 | { |
| 127 | std::string message; |
| 128 | // TODO: consider enabling color |
| 129 | std::string formattedMessage = SourceReferenceFormatter::formatExceptionInformation( |
| 130 | _exception, |
| 131 | _type, |
| 132 | _charStreamProvider, |
| 133 | false // colored |
| 134 | ); |
| 135 | |
| 136 | if (std::string const* description = _exception.comment()) |
| 137 | message = ((_message.length() > 0) ? (_message + ": ") : "") + *description; |
| 138 | else |
| 139 | message = _message; |
| 140 | |
| 141 | Json error = formatError( |
| 142 | _type, |
| 143 | _component, |
| 144 | message, |
| 145 | formattedMessage, |
| 146 | formatSourceLocation(boost::get_error_info<errinfo_sourceLocation>(_exception)), |
| 147 | formatSecondarySourceLocation(boost::get_error_info<errinfo_secondarySourceLocation>(_exception)) |
| 148 | ); |
| 149 | |
| 150 | if (_errorId) |
| 151 | error["errorCode"] = std::to_string(_errorId.value().error); |
| 152 | |
| 153 | return error; |
| 154 | } |
| 155 | |
| 156 | /// Returns true iff @a _hash (hex with 0x prefix) is the Keccak256 hash of the binary data in @a _content. |
| 157 | bool hashMatchesContent(std::string const& _hash, std::string const& _content) |
no test coverage detected