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

Add a way to temporarily disable error printing in the engine #1763

Closed
Xrayez opened this issue Nov 2, 2020 · 3 comments · Fixed by godotengine/godot#48359
Closed

Add a way to temporarily disable error printing in the engine #1763

Xrayez opened this issue Nov 2, 2020 · 3 comments · Fixed by godotengine/godot#48359
Milestone

Comments

@Xrayez
Copy link
Contributor

Xrayez commented Nov 2, 2020

Describe the project you are working on:
Goost Godot Engine extension.

Describe the problem or limitation you are having in your project:
I happen to write unit test in GDScript using GUT, and this works well for most cases. I also want to test for failure paths from within GDScript itself for best coverage (like testing bad index to prevent crashes). The problem is that these kind of erroneous operations produce error prints in the debugger and console:

func test_choice_empty():
	# Should not crash.
	assert_null(Random.choice(""))
	assert_null(Random.choice([]))

goost_err_catch_ok

The above problem can be seen in goostengine/goost#31.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
I propose adding a method which allows to dynamically enable and disable error printing. Having ability to temporarily disable those errors allows to filter out the noise coming from "expected failures" seen in tests.

I've even written unit testing documentation describing this technique in Testing failure paths section when writing unit tests in C++. The same thing should be possible to do from within Godot to work both in the console and the editor.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
The approach would be similar to existing ERR_PRINT_ON and ERR_PRINT_OFF test macros in tests/test_macros.h. The method can be added to OS singleton, such as OS::set_error_print_enabled(). The missing part is that it should also apply to Godot's debugger in the editor.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
Impossible to prevent error prints in the debugger selectively. It's possible to disable error printing via application/run/disable_stderr project setting, but that only prevents terminal output, and the idea here is that it should be possible to do this at run-time as well.

Is there a reason why this should be core and not an add-on in the asset library?:
Can only be done on the engine level.

@Calinou
Copy link
Member

Calinou commented Nov 2, 2020

Maybe this should be a property in the Engine singleton which can be set at run-time?

Engine.print_errors = true/false

@Xrayez Xrayez changed the title Add a method to temporarily disable error printing in the engine Add a way to temporarily disable error printing in the engine Nov 3, 2020
@akien-mga akien-mga added this to the 4.0 milestone Jun 20, 2021
@Xrayez
Copy link
Contributor Author

Xrayez commented Jul 19, 2021

Could godotengine/godot#48359 be backported to 3.x? I'm in dire need for this in 3.x, see for instance goostengine/goost#106.

I can do this myself if approved.

@Calinou
Copy link
Member

Calinou commented Jul 19, 2021

Could godotengine/godot#48359 be backported to 3.x? I'm in dire need for this in 3.x, see for instance goostengine/goost#106.

I can do this myself if approved.

Sure, feel free to backport it to 3.x 🙂

Make sure to port the documentation changes I did in that PR as well.

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

Successfully merging a pull request may close this issue.

3 participants