1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

VariantParser: Ensure all parse errors have an explanation

Likewise in ResourceFormatText and JSON.
This commit is contained in:
Rémi Verschelde
2024-07-18 14:17:05 +02:00
parent bdf625bd54
commit c049d07121
3 changed files with 40 additions and 38 deletions

View File

@@ -198,7 +198,7 @@ Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_to
String str;
while (true) {
if (p_str[index] == 0) {
r_err_str = "Unterminated String";
r_err_str = "Unterminated string";
return ERR_PARSE_ERROR;
} else if (p_str[index] == '"') {
index++;
@@ -208,7 +208,7 @@ Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_to
index++;
char32_t next = p_str[index];
if (next == 0) {
r_err_str = "Unterminated String";
r_err_str = "Unterminated string";
return ERR_PARSE_ERROR;
}
char32_t res = 0;
@@ -234,7 +234,7 @@ Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_to
for (int j = 0; j < 4; j++) {
char32_t c = p_str[index + j + 1];
if (c == 0) {
r_err_str = "Unterminated String";
r_err_str = "Unterminated string";
return ERR_PARSE_ERROR;
}
if (!is_hex_digit(c)) {
@@ -270,7 +270,7 @@ Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_to
for (int j = 0; j < 4; j++) {
char32_t c = p_str[index + j + 1];
if (c == 0) {
r_err_str = "Unterminated String";
r_err_str = "Unterminated string";
return ERR_PARSE_ERROR;
}
if (!is_hex_digit(c)) {
@@ -313,7 +313,7 @@ Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_to
res = next;
} break;
default: {
r_err_str = "Invalid escape sequence.";
r_err_str = "Invalid escape sequence";
return ERR_PARSE_ERROR;
}
}
@@ -361,19 +361,20 @@ Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_to
r_token.value = id;
return OK;
} else {
r_err_str = "Unexpected character.";
r_err_str = "Unexpected character";
return ERR_PARSE_ERROR;
}
}
}
}
r_err_str = "Unknown error getting token";
return ERR_PARSE_ERROR;
}
Error JSON::_parse_value(Variant &value, Token &token, const char32_t *p_str, int &index, int p_len, int &line, int p_depth, String &r_err_str) {
if (p_depth > Variant::MAX_RECURSION_DEPTH) {
r_err_str = "JSON structure is too deep. Bailing.";
r_err_str = "JSON structure is too deep";
return ERR_OUT_OF_MEMORY;
}
@@ -400,7 +401,7 @@ Error JSON::_parse_value(Variant &value, Token &token, const char32_t *p_str, in
} else if (id == "null") {
value = Variant();
} else {
r_err_str = "Expected 'true','false' or 'null', got '" + id + "'.";
r_err_str = vformat("Expected 'true', 'false', or 'null', got '%s'", id);
return ERR_PARSE_ERROR;
}
} else if (token.type == TK_NUMBER) {
@@ -408,7 +409,7 @@ Error JSON::_parse_value(Variant &value, Token &token, const char32_t *p_str, in
} else if (token.type == TK_STRING) {
value = token.value;
} else {
r_err_str = "Expected value, got " + String(tk_name[token.type]) + ".";
r_err_str = vformat("Expected value, got '%s'", String(tk_name[token.type]));
return ERR_PARSE_ERROR;
}