| 1 | #include "simdjson/simdjson.h" |
| 2 | #include <map> |
| 3 | |
| 4 | namespace simdjson { |
| 5 | const std::map<int, const std::string> error_strings = { |
| 6 | {SUCCESS, "No errors" }, |
| 7 | {SUCCESS_AND_HAS_MORE, "No errors and buffer still has more data" }, |
| 8 | {CAPACITY, "This ParsedJson can't support a document that big" }, |
| 9 | {MEMALLOC, "Error allocating memory, we're most likely out of memory" }, |
| 10 | {TAPE_ERROR, "Something went wrong while writing to the tape" }, |
| 11 | {STRING_ERROR, "Problem while parsing a string" }, |
| 12 | {T_ATOM_ERROR, |
| 13 | "Problem while parsing an atom starting with the letter 't'" }, |
| 14 | {F_ATOM_ERROR, |
| 15 | "Problem while parsing an atom starting with the letter 'f'" }, |
| 16 | {N_ATOM_ERROR, |
| 17 | "Problem while parsing an atom starting with the letter 'n'" }, |
| 18 | {NUMBER_ERROR, "Problem while parsing a number" }, |
| 19 | {UTF8_ERROR, "The input is not valid UTF-8" }, |
| 20 | {UNITIALIZED, "Unitialized" }, |
| 21 | {EMPTY, "Empty: no JSON found" }, |
| 22 | {UNESCAPED_CHARS, "Within strings, some characters must be escaped, we " |
| 23 | "found unescaped characters" }, |
| 24 | {UNCLOSED_STRING, "A string is opened, but never closed." }, |
| 25 | {UNEXPECTED_ERROR, "Unexpected error, consider reporting this problem as " |
| 26 | "you may have found a bug in simdjson" }, |
| 27 | }; |
| 28 | |
| 29 | // string returned when the error code is not recognized |
| 30 | const std::string unexpected_error_msg {"Unexpected error" }; |
| 31 | |
| 32 | // returns a string matching the error code |
| 33 | const std::string &error_message(const int error_code) { |
| 34 | auto keyvalue = error_strings.find(error_code); |
| 35 | if(keyvalue == error_strings.end()) { |
| 36 | return unexpected_error_msg; |
| 37 | } |
| 38 | return keyvalue->second; |
| 39 | } |
| 40 | } // namespace simdjson |
| 41 | |