Getting GdScript warnings through the command line?

Godot Version

4.5

Question

When running Godot from the command line errors are clearly printed.
However I haven’t found a way to also get the compiler warnings out without a language server or the Godot Editor.

Ideally, I’d like to pass in a flag that would make the godot binary print compilation warnings (with filename + line number) to stdout/stderr like this one below:

(UNSAFE_METHOD_ACCESS): The method "is_empty()" is not present on the inferred type "Variant" (but may be present on a subtype)."

For me the use case would be audit/presubmit scripts that would prevent new warnings to be introduced in certain part of the codebase.
(E.g. certain submodule can’t have a certain kind of warning. Or this type of warning is only okay in test code)

Does OS.add_logger() do what you want?

You can use --script <script> to only run that script and --check-only to only check for errors. If you need warnings too then add --debug

So it would be:

$ ./godot --script my_script.gd --check-only --debug

More command line parameters:

1 Like

Thank you, this is very close to what I needed and it does give the compiler warnings on the command line for some of my scripts. :folded_hands:

I’ll need to figure out how to run it in bulk efficiently on all the scripts in a directory, but before that I’m running into an issue.

If the script I’m loading uses an Addon (in my case it’s the Log addon) the script won’t compile and also the Godot binary crashes afterwards.

Here’s the output I’m getting:

godot --script test/tools/damage_matrix_calculator.gd --check-only --debug --headless
Godot Engine v4.5.stable.official.876b29033 - https://godotengine.org
Requested V-Sync mode: Enabled - FPS will likely be capped to the monitor refresh rate.

SCRIPT ERROR: Compile Error: Identifier not found: Log
          at: GDScript::reload (res://model/hex/coords_util.gd:180)

Debugger Break, Reason: 'Parser Error: Identifier not found: Log'
*Frame 0 - res://model/hex/coords_util.gd:180 in function ''
Enter "help" for assistance.
debug> q

================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.5.stable.official (876b290332ec6f2e6d173d08162a02aa7e6ca46d)
Dumping the backtrace. Please include this when reporting the bug on: https://github.com/godotengine/godot/issues
[1] 1   libsystem_platform.dylib            0x0000000181dd56a4 _sigtramp + 56
[2] icudt_godot77_dat (in Godot) + 4128508
[3] icudt_godot77_dat (in Godot) + 4181192
[4] TextEdit::set_selection_origin_column(int, int) (in Godot) + 156
[5] ScrollContainer::_bind_methods() (in Godot) + 7688
[6] TextEdit::_update_scrollbars() (in Godot) + 924
[7] TextEdit::get_caret_line(int) const (in Godot) + 72
[8] _editor_translation_el_compressed (in Godot) + 7100
[9] ScrollContainer::_bind_methods() (in Godot) + 6824
[10] TextEdit::_update_scrollbars() (in Godot) + 924
[11] TextEdit::get_caret_line(int) const (in Godot) + 72
[12] _editor_translation_el_compressed (in Godot) + 7100
[13] ScrollContainer::_bind_methods() (in Godot) + 6824
[14] TextEdit::_update_scrollbars() (in Godot) + 924
[15] SpinBox::set_suffix(String const&) (in Godot) + 108
[16] icudt_godot77_dat (in Godot) + 3858432
[17] icudt_godot77_dat (in Godot) + 3862240
[18] icudt_godot77_dat (in Godot) + 3870204
[19] icudt_godot77_dat (in Godot) + 3871948
[20] Main::start()
^C[21]
[22] EditorVCSInterface::_bind_methods() (in Godot) + 7940
[23] 23  dyld                                0x00000001819fab98 start + 6076
-- END OF C++ BACKTRACE --
================================================================
Abort trap: 6

This is on Mac OS (Godot 4.5).

Any advice on how to proceed or get around this?


Update: it might actually be related to a threading issue in the addon I’m using…

Can you post the guts of model/hex/coords_util.gd? That error look like you’re referencing Log on line 180 of that file without it being defined…

Unfortunately it is neither my code, nor the addon I’m using.
It seems this is a general bug: --check-only seems to break if you call singletons added by plugins.

I filed a bug here:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.