Skip to content

Commit 155f94a

Browse files
committed
Merge pull request #97370 from RandomShaper/refix_rl_not_found
ResourceLoader: Report error if resource type unrecognized
2 parents 827a525 + fe21913 commit 155f94a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

core/io/resource_loader.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,13 @@ Ref<Resource> ResourceLoader::_load(const String &p_path, const String &p_origin
282282
load_paths_stack.push_back(original_path);
283283

284284
// Try all loaders and pick the first match for the type hint
285-
bool found = false;
285+
bool loader_found = false;
286286
Ref<Resource> res;
287287
for (int i = 0; i < loader_count; i++) {
288288
if (!loader[i]->recognize_path(p_path, p_type_hint)) {
289289
continue;
290290
}
291-
found = true;
291+
loader_found = true;
292292
res = loader[i]->load(p_path, original_path, r_error, p_use_sub_threads, r_progress, p_cache_mode);
293293
if (!res.is_null()) {
294294
break;
@@ -303,15 +303,24 @@ Ref<Resource> ResourceLoader::_load(const String &p_path, const String &p_origin
303303
return res;
304304
}
305305

306-
ERR_FAIL_COND_V_MSG(found, Ref<Resource>(),
307-
vformat("Failed loading resource: %s. Make sure resources have been imported by opening the project in the editor at least once.", p_path));
306+
if (!loader_found) {
307+
if (r_error) {
308+
*r_error = ERR_FILE_UNRECOGNIZED;
309+
}
310+
ERR_FAIL_V_MSG(Ref<Resource>(), vformat("No loader found for resource: %s (expected type: %s)", p_path, p_type_hint));
311+
}
308312

309313
#ifdef TOOLS_ENABLED
310314
Ref<FileAccess> file_check = FileAccess::create(FileAccess::ACCESS_RESOURCES);
311-
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));
315+
if (!file_check->file_exists(p_path)) {
316+
if (r_error) {
317+
*r_error = ERR_FILE_NOT_FOUND;
318+
}
319+
ERR_FAIL_V_MSG(Ref<Resource>(), vformat("Resource file not found: %s (expected type: %s)", p_path, p_type_hint));
320+
}
312321
#endif
313322

314-
ERR_FAIL_V_MSG(Ref<Resource>(), vformat("No loader found for resource: %s (expected type: %s)", p_path, p_type_hint));
323+
ERR_FAIL_V_MSG(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));
315324
}
316325

317326
// This implementation must allow re-entrancy for a task that started awaiting in a deeper stack frame.

0 commit comments

Comments
 (0)