Skip to content

Commit f79b972

Browse files
committed
ResourceLoader: Report appropriate error code when no suitable loader is found
1 parent 9e60984 commit f79b972

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
@@ -316,14 +316,34 @@ Ref<Resource> ResourceLoader::_load(const String &p_path, const String &p_origin
316316
return res;
317317
}
318318

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

322334
#ifdef TOOLS_ENABLED
323335
Ref<FileAccess> file_check = FileAccess::create(FileAccess::ACCESS_RESOURCES);
324-
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));
336+
if (!file_check->file_exists(p_path)) {
337+
if (r_error) {
338+
*r_error = ERR_FILE_NOT_FOUND;
339+
}
340+
ERR_FAIL_V_MSG(Ref<Resource>(), vformat("Resource file not found: %s (expected type: %s)", p_path, p_type_hint));
341+
}
325342
#endif
326343

344+
if (r_error) {
345+
*r_error = ERR_FILE_UNRECOGNIZED;
346+
}
327347
ERR_FAIL_V_MSG(Ref<Resource>(), vformat("No loader found for resource: %s (expected type: %s)", p_path, p_type_hint));
328348
}
329349

0 commit comments

Comments
 (0)