From f79b972d0d67647a3438599a1fce9862ea58d9ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Thu, 21 Nov 2024 13:31:48 +0100 Subject: [PATCH] ResourceLoader: Report appropriate error code when no suitable loader is found --- core/io/resource_loader.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 1615f145db2..fbd9fd7d2db 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -316,14 +316,34 @@ Ref ResourceLoader::_load(const String &p_path, const String &p_origin return res; } +#ifdef TOOLS_ENABLED + if (Engine::get_singleton()->is_editor_hint()) { + if (ResourceFormatImporter::get_singleton()->get_importer_by_extension(p_path.get_extension()).is_valid()) { + // The format is known to the editor, but the file hasn't been imported + // (otherwise, ResourceFormatImporter would have been found as a suitable loader). + found = true; + if (r_error) { + *r_error = ERR_FILE_NOT_FOUND; + } + } + } +#endif ERR_FAIL_COND_V_MSG(found, Ref(), vformat("Failed loading resource: %s. Make sure resources have been imported by opening the project in the editor at least once.", p_path)); #ifdef TOOLS_ENABLED Ref file_check = FileAccess::create(FileAccess::ACCESS_RESOURCES); - ERR_FAIL_COND_V_MSG(!file_check->file_exists(p_path), Ref(), vformat("Resource file not found: %s (expected type: %s)", p_path, p_type_hint)); + if (!file_check->file_exists(p_path)) { + if (r_error) { + *r_error = ERR_FILE_NOT_FOUND; + } + ERR_FAIL_V_MSG(Ref(), vformat("Resource file not found: %s (expected type: %s)", p_path, p_type_hint)); + } #endif + if (r_error) { + *r_error = ERR_FILE_UNRECOGNIZED; + } ERR_FAIL_V_MSG(Ref(), vformat("No loader found for resource: %s (expected type: %s)", p_path, p_type_hint)); }