VariantParser: Ensure all parse errors have an explanation
Likewise in ResourceFormatText and JSON.
This commit is contained in:
parent
bdf625bd54
commit
c049d07121
3 changed files with 40 additions and 38 deletions
|
|
@ -35,10 +35,8 @@
|
|||
#include "core/io/missing_resource.h"
|
||||
#include "core/object/script_language.h"
|
||||
|
||||
///
|
||||
|
||||
void ResourceLoaderText::_printerr() {
|
||||
ERR_PRINT(String(res_path + ":" + itos(lines) + " - Parse Error: " + error_text).utf8().get_data());
|
||||
ERR_PRINT(vformat("%s:%d - Parse Error: %s.", res_path, lines, error_text));
|
||||
}
|
||||
|
||||
Ref<Resource> ResourceLoaderText::get_resource() {
|
||||
|
|
@ -242,7 +240,7 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars
|
|||
|
||||
if (packed_scene->get_state()->get_node_count() == 0) {
|
||||
error = ERR_FILE_CORRUPT;
|
||||
error_text = "Instance Placeholder can't be used for inheritance.";
|
||||
error_text = "Instance Placeholder can't be used for inheritance";
|
||||
_printerr();
|
||||
return Ref<PackedScene>();
|
||||
}
|
||||
|
|
@ -372,7 +370,7 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars
|
|||
} else if (next_tag.name == "editable") {
|
||||
if (!next_tag.fields.has("path")) {
|
||||
error = ERR_FILE_CORRUPT;
|
||||
error_text = "missing 'path' field from editable tag";
|
||||
error_text = "Missing 'path' field from editable tag";
|
||||
_printerr();
|
||||
return Ref<PackedScene>();
|
||||
}
|
||||
|
|
@ -394,6 +392,7 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars
|
|||
}
|
||||
} else {
|
||||
error = ERR_FILE_CORRUPT;
|
||||
error_text = vformat("Unknown tag '%s' in file", next_tag.name);
|
||||
_printerr();
|
||||
return Ref<PackedScene>();
|
||||
}
|
||||
|
|
@ -547,7 +546,7 @@ Error ResourceLoaderText::load() {
|
|||
missing_resource->set_recording_properties(true);
|
||||
obj = missing_resource;
|
||||
} else {
|
||||
error_text += "Can't create sub resource of type: " + type;
|
||||
error_text = vformat("Can't create sub resource of type '%s'", type);
|
||||
_printerr();
|
||||
error = ERR_FILE_CORRUPT;
|
||||
return error;
|
||||
|
|
@ -556,7 +555,7 @@ Error ResourceLoaderText::load() {
|
|||
|
||||
Resource *r = Object::cast_to<Resource>(obj);
|
||||
if (!r) {
|
||||
error_text += "Can't create sub resource of type, because not a resource: " + type;
|
||||
error_text = vformat("Can't create sub resource of type '%s' as it's not a resource type", type);
|
||||
_printerr();
|
||||
error = ERR_FILE_CORRUPT;
|
||||
return error;
|
||||
|
|
@ -668,7 +667,7 @@ Error ResourceLoaderText::load() {
|
|||
}
|
||||
|
||||
if (is_scene) {
|
||||
error_text += "found the 'resource' tag on a scene file!";
|
||||
error_text = "Unexpected 'resource' tag in a scene file";
|
||||
_printerr();
|
||||
error = ERR_FILE_CORRUPT;
|
||||
return error;
|
||||
|
|
@ -693,7 +692,7 @@ Error ResourceLoaderText::load() {
|
|||
missing_resource->set_recording_properties(true);
|
||||
obj = missing_resource;
|
||||
} else {
|
||||
error_text += "Can't create sub resource of type: " + res_type;
|
||||
error_text = vformat("Can't create sub resource of type '%s'", res_type);
|
||||
_printerr();
|
||||
error = ERR_FILE_CORRUPT;
|
||||
return error;
|
||||
|
|
@ -702,7 +701,7 @@ Error ResourceLoaderText::load() {
|
|||
|
||||
Resource *r = Object::cast_to<Resource>(obj);
|
||||
if (!r) {
|
||||
error_text += "Can't create sub resource of type, because not a resource: " + res_type;
|
||||
error_text = vformat("Can't create sub resource of type '%s' as it's not a resource type", res_type);
|
||||
_printerr();
|
||||
error = ERR_FILE_CORRUPT;
|
||||
return error;
|
||||
|
|
@ -815,7 +814,7 @@ Error ResourceLoaderText::load() {
|
|||
|
||||
if (next_tag.name == "node") {
|
||||
if (!is_scene) {
|
||||
error_text += "found the 'node' tag on a resource file!";
|
||||
error_text = "Unexpected 'node' tag in a resource file";
|
||||
_printerr();
|
||||
error = ERR_FILE_CORRUPT;
|
||||
return error;
|
||||
|
|
@ -847,7 +846,7 @@ Error ResourceLoaderText::load() {
|
|||
|
||||
return error;
|
||||
} else {
|
||||
error_text += "Unknown tag in file: " + next_tag.name;
|
||||
error_text = vformat("Unknown tag '%s' in file", next_tag.name);
|
||||
_printerr();
|
||||
error = ERR_FILE_CORRUPT;
|
||||
return error;
|
||||
|
|
@ -1114,7 +1113,7 @@ void ResourceLoaderText::open(Ref<FileAccess> p_f, bool p_skip_first_tag) {
|
|||
res_type = tag.fields["type"];
|
||||
|
||||
} else {
|
||||
error_text = "Unrecognized file type: " + tag.name;
|
||||
error_text = vformat("Unrecognized file type '%s'", tag.name);
|
||||
_printerr();
|
||||
error = ERR_PARSE_ERROR;
|
||||
return;
|
||||
|
|
@ -1218,9 +1217,9 @@ Error ResourceLoaderText::get_classes_used(HashSet<StringName> *r_classes) {
|
|||
// This is a node, must save one more!
|
||||
|
||||
if (!is_scene) {
|
||||
error_text += "found the 'node' tag on a resource file!";
|
||||
_printerr();
|
||||
error = ERR_FILE_CORRUPT;
|
||||
error_text = "Unexpected 'node' tag in a resource file";
|
||||
_printerr();
|
||||
return error;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue