el-falso / gdlinter

This plugin runs `gdlint` on save to automatically lint your GD Script as you code.
https://godotengine.org/asset-library/asset/2520
MIT License
15 stars 5 forks source link

recurrent error " Invalid get index 'strings' (on base: 'null instance')." #4

Closed LaurentOngaro closed 5 months ago

LaurentOngaro commented 6 months ago

I'm creating a project in Godot 4.2.1 with the latest version of your add on available on the Asset lib

The following error occurs very often when I'm editing a GD script file and I can"t really found what causes it. It appears "randomly", not each time I open a script.

  res://addons/gdLinter/gdLinter.gd:105 - Invalid get index 'strings' (on base: 'null instance').
    Exit code: 1
  Format GDScript failed: res://src/scripts/game_manager.gd
  res://addons/gdLinter/gdLinter.gd:105 - Invalid get index 'strings' (on base: 'null instance').
(3) ["Success: no problems found\r", ""]

My project is just a simple scene with a Node2D (Main) as root, and a child Node (GameManager) with a script attached I just opened the script it and I have the error in the output panel

image

AINPCs_ISSUE_1.zip AINPCs_ISSUE_2.zip

I've joined a simpler version of my project.

rename AINPCs_ISSUE_1.zip to AINPCs_ISSUE.zip.001 AINPCs_ISSUE_2.zip to AINPCs_ISSUE.zip.002 and unzip to get the sources of the project

el-falso commented 6 months ago

This issue should already be fixed in the commits, see: https://github.com/el-falso/gdlinter/issues/1

I just did not push a new release, because I wanted to wait for version 2.0. But I released version 1.0.1 now which you can try out: https://github.com/el-falso/gdlinter/releases/tag/v1.0.1

LaurentOngaro commented 6 months ago

I've tried the 1.0.1 version, but there are still errors when I'm trying to format the ErrorButton.gd file (I've joined my modified version)

Godot Engine v4.2.1.stable.official (c) 2007-present Juan Linietsky, Ariel Manzur & Godot Contributors.
--- Debug adapter server started ---
--- GDScript language server started on port 6005 ---
Add Autoload
Found a repository at D:/Projets_Godot/V42/_Addons/log_and_box/.git/.
Selected repository path: D:/Projets_Godot/V42/_Addons/log_and_box/.git/.
FileSystemView: load defaultConfig.json
  (2) res://addons/gdLinter/UI/ErrorButton.gd:66 - Out of bounds get index '-1' (on base: 'Array[RegExMatch]')
Loading GDLint Plugin success
    Exit code: 1
  Format GDScript failed: res://tests/logtest.tscn::GDScript_q0mxg
  (4) res://addons/gdLinter/UI/ErrorButton.gd:66 - Out of bounds get index '-1' (on base: 'Array[RegExMatch]')

I've change the _ready() function in Errorbutton.gd as follow to make a test:

func _ready() -> void:
    modulate = color

    icon = EditorInterface.get_editor_theme().get_icon("Error", "EditorIcons")

    var regex = RegEx.new()
    regex.compile("(?<=\\()[^\\)]+")
    var result := regex.search_all(text)
    if len(result)>1:
        print_rich(result[-1])
        var error_type := str(result[-1])
        if error.has(error_type):
            tooltip_text = error[error_type]

and now the result is:

<RegExMatch#-9223367909860896704>
<RegExMatch#-9223367909709910433>
    Exit code: 1
  Format GDScript failed: res://addons/gdLinter/UI/ErrorButton.gd

not many information here, so I've test the format the file using the command line : gdformat .\addons\gdLinter\UI\ErrorButton.gd

and the result is:

.\addons\gdLinter\UI\ErrorButton.gd: Failed to format,some comments are missing in formatted code
0 files reformatted, 1 file left unchanged.

ErrorButton.zip

el-falso commented 5 months ago

I just released version 2.0.0 which provides fixes and since the file ErrorButton.gd isn't used anymore this issue should also be fixed, can you confirm this? Since this is a major version change, delete the old gdlinter folder before using the new files from version 2.0.0

https://github.com/el-falso/gdlinter/releases/latest

LaurentOngaro commented 5 months ago

I'm currently testing the new version BUT there is an issue with the path of glint exe. I've got the error:

Could not create child process: bin\gdlint --version

when my project start The previous version did not throw this error with the same project code.

I'm using Godot in Windows I think the error is in the get_gdlint_path() function because on Windows, the default exe for running python is python and not python3

Changing the exe name in this function with produce another error

Could not create child process: C:\Users\laure\AppData\Roaming\Python\bin\gdlint --version

that's because the "python --version" commands only returns Python 3.12.1 (on windows), with no path information for the binary

For a quick workarround, if I replace the get_gdlint_path() function with the following code

func get_gdlint_path() -> String:
    if OS.get_name() == "Windows":
        return "gdlint"
    else:
        var output := []
        OS.execute("python3", ["-m", "site", "--user-base"], output)
        var python_bin_folder := (output[0] as String).strip_edges().path_join("bin")
        return python_bin_folder.path_join("gdlint")

to mimic to behavior of your previous version

Now, the linter runs fine BUT I still have the following error on any file a save

res://addons/gdLinter/gdLinter.gd:121 - Invalid get index 'strings' (on base: 'null instance').

to fix that, I've changed the following lines in gdLinter.gd (line 121 and after)

    if result:
        var current_line := int(result.strings[0])-1
        var error := output_array[i].rsplit(":", true, 1)
        if len(error)>1:
            _dock_ui.create_item(current_line+1, error[1])
            if _dock_ui.is_error_ignored(error[1]):
                continue
            highlight_lines.append(current_line)

Now, all runs well

el-falso commented 5 months ago

Thank you for providing the fix for these two issues.

I have to admit: I was already worried because of python3 on Windows, but since I can use on my installation both, python and python3, I didn't care this much.

LaurentOngaro commented 5 months ago

You're welcome and thanks for your work too !

The 2.0.1 version runs fine. Perhaps you should run glint on your gdlinter.gd because I've some minor warnings after each update:

el-falso commented 5 months ago

Since gdlinter lints the files on save, I know that there are minor warnings, but that's where ignoring rules are useful. Also: The source code of gdlinter shouldn't be a perfect example in following every rule.