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

Improve ResourceLoader error handling #11528

Open
AlixBarreaux opened this issue Jan 9, 2025 · 0 comments
Open

Improve ResourceLoader error handling #11528

AlixBarreaux opened this issue Jan 9, 2025 · 0 comments

Comments

@AlixBarreaux
Copy link

AlixBarreaux commented Jan 9, 2025

Describe the project you are working on

A save system which uses resources.

Describe the problem or limitation you are having in your project

I can't handle specific errors when I try to load my custom resource file in contrast to FileAccess.get_open_error() .
If an error occurs I'd like to know more about what caused it and having an error code is useful. Except there is none in ResourceLoader.
When an error occurs it is only printed in the debugger but it can't be used in the code directly.

The problem is explained entirely here: https://forum.godotengine.org/t/how-to-handle-resource-loading-error-resourceloader-load/97628

Describe the feature / enhancement and how it helps to overcome the problem or limitation

I'd like to have a method in ResourceLoader with the same behavior than FileAccess.get_open_error() : A method which returns an error code when trying to load the resource.
Using the error code it'd help for things such as handling the error in the code, displaying a user friendly message to the player and many other useful things.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

# Let's assume ResourceLoader.get_open_error() is the method I want to use
var save_game: Resource = load("user://my_resource.tres")
var error = ResourceLoader.get_open_error()
if error == ERR_FILE_NOT_FOUND:
	print("File not found, create a new file with default values.")
elif error == ERR_FILE_NO_PERMISSION:
        printerr("Can't open the file: Permission denied!")
elif error != OK:
	printerr("An unhandled error has occured. Error code: " + str(error))

If this enhancement will not be used often, can it be worked around with a few lines of script?

For now the only way I have found to handle errors without much control over it is:

var resource: Resource = load("user://my_resource.tres")
	if resource == null:
		printerr("An unhandled error occured!")

Is there a reason why this should be core and not an add-on in the asset library?

I didn't find any way to handle errors via GDScript. FileAccess.get_open_error() has exactly this feature but I think loading a resource via ResourceLoader can have errors which are different from FileAccess under the hood. (EG: The resource file values mismatch, the file is not of type resource, etc...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants