Skip to content

Commit 0c0c45d

Browse files
committed
Merge pull request godotengine#99494 from RandomShaper/rerefix_res_unrecog
ResourceLoader: Report appropriate error code when no suitable loader is found
2 parents ec85334 + f79b972 commit 0c0c45d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

core/io/resource_loader.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,34 @@ Ref<Resource> ResourceLoader::_load(const String &p_path, const String &p_origin
320320
print_verbose(vformat("Failed loading resource: %s", p_path));
321321
}
322322

323+
#ifdef TOOLS_ENABLED
324+
if (Engine::get_singleton()->is_editor_hint()) {
325+
if (ResourceFormatImporter::get_singleton()->get_importer_by_extension(p_path.get_extension()).is_valid()) {
326+
// The format is known to the editor, but the file hasn't been imported
327+
// (otherwise, ResourceFormatImporter would have been found as a suitable loader).
328+
found = true;
329+
if (r_error) {
330+
*r_error = ERR_FILE_NOT_FOUND;
331+
}
332+
}
333+
}
334+
#endif
323335
ERR_FAIL_COND_V_MSG(found, Ref<Resource>(),
324336
vformat("Failed loading resource: %s. Make sure resources have been imported by opening the project in the editor at least once.", p_path));
325337

326338
#ifdef TOOLS_ENABLED
327339
Ref<FileAccess> file_check = FileAccess::create(FileAccess::ACCESS_RESOURCES);
328-
ERR_FAIL_COND_V_MSG(!file_check->file_exists(p_path), Ref<Resource>(), vformat("Resource file not found: %s (expected type: %s)", p_path, p_type_hint));
340+
if (!file_check->file_exists(p_path)) {
341+
if (r_error) {
342+
*r_error = ERR_FILE_NOT_FOUND;
343+
}
344+
ERR_FAIL_V_MSG(Ref<Resource>(), vformat("Resource file not found: %s (expected type: %s)", p_path, p_type_hint));
345+
}
329346
#endif
330347

348+
if (r_error) {
349+
*r_error = ERR_FILE_UNRECOGNIZED;
350+
}
331351
ERR_FAIL_V_MSG(Ref<Resource>(), vformat("No loader found for resource: %s (expected type: %s)", p_path, p_type_hint));
332352
}
333353

0 commit comments

Comments
 (0)