Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceLoader: Report appropriate error code when no suitable loader is found #99494

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ResourceLoader: Report appropriate error code when no suitable loader…
… is found
RandomShaper committed Nov 21, 2024
commit f79b972d0d67647a3438599a1fce9862ea58d9ad
22 changes: 21 additions & 1 deletion core/io/resource_loader.cpp
Original file line number Diff line number Diff line change
@@ -316,14 +316,34 @@ Ref<Resource> ResourceLoader::_load(const String &p_path, const String &p_origin
return res;
}

#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restricting this to editor sessions (and not just editor builds) because at runtime many types are not registered with the importer and therefore the check below would be less reliable. That way, we have two behaviors only: editor and runtime, and not an in-between third one, that would make things unnecessarily complex.

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<Resource>(),
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<FileAccess> file_check = FileAccess::create(FileAccess::ACCESS_RESOURCES);
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));
if (!file_check->file_exists(p_path)) {
if (r_error) {
*r_error = ERR_FILE_NOT_FOUND;
}
ERR_FAIL_V_MSG(Ref<Resource>(), 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<Resource>(), vformat("No loader found for resource: %s (expected type: %s)", p_path, p_type_hint));
}