redromnon / HeroicBashLauncher

Directly launch any Epic Games Store and GOG game from anywhere without Heroic on Linux.
GNU General Public License v3.0
354 stars 17 forks source link

[Bug] AttributeError: 'Namespace' object has no attribute 'silent' #127

Open nerdneilsfield opened 1 year ago

nerdneilsfield commented 1 year ago

Describe the bug

can not run the HeroicBash Luancher, AttributeError: 'Namespace' object has no attribute 'silent'

Expected behavior

the script should run and add the games to Steam Library

Screenshots

log

(deck@steamdeck HeroicBashLauncher)$ ./HeroicBashLauncher 
Using Bash Launcher v3.2.2
NOTE - This is an independent project and not affiliated with Heroic Games Launcher.

3.32.0
Traceback (most recent call last):
  File "func/HeroicBashLauncher.py", line 69, in <module>
  File "func/listinstalled.py", line 50, in listinstalled
  File "func/createlaunchfile.py", line 17, in createlaunchfile
AttributeError: 'Namespace' object has no attribute 'silent'
[1321720] Failed to execute script 'HeroicBashLauncher' due to unhandled exception!

Details

Additional context None

redromnon commented 1 year ago

This issue is the same as #125 Looking into it.

nerdneilsfield commented 1 year ago

Thanks

redromnon commented 1 year ago

Hey @afwolfe, do you know a solution to this? I've not encountered it on my side but several users are complaining. Linked a commit I made to kind of refactor it.

redromnon commented 1 year ago

@nerdneilsfield Can you check if this build works? Just replace the executable with the one in the Bash Launcher folder.

afwolfe commented 1 year ago

Hey @redromnon. It took some digging and trial and error but I think I was able to figure it out.

In order to debug with VS Code, I had to do the following to get HeroicBashLauncher to work without being bundled up by PyInstaller and being in the Games/Heroic/HeroicBashLauncher directory (please let me know if there's a better way to do this):

  1. Copying HeroicBashLauncher.py to the root of the repo (because it didn't like the func imports while it was in the same directory.)
  2. Using this launch.json: (replacing ${REPLACE_WITH_PATH_TO_HOME})
    {
    "version": "0.2.0",
    "configurations": [
        {
            "name": "HeroicBashLauncher",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/HeroicBashLauncher.py",
            "cwd": "${REPLACE_WITH_PATH_TO_HOME}/Games/Heroic/HeroicBashLauncher/",
            "console": "integratedTerminal",
            "justMyCode": true
        }
    ]
    }
  3. I set a breakpoint at createlaunchfile.py:11 and confirmed that args is None when imported. On the fix-args-parser branch args is a Namespace, but it looks like args.silent is still unset and will throw the AttributeError: 'Namespace' object has no attribute 'silent'.

After a bit more searching, I think this StackOverflow does a good job explaining the bug which seems to relate to the visibility of global variables in imported modules: https://stackoverflow.com/questions/15959534/visibility-of-global-variables-in-imported-modules Especially this in the top answer from abarnert:

Don't use a from import unless the variable is intended to be a constant. from shared_stuff import a would create a new a variable initialized to whatever shared_stuff.a referred to at the time of the import, and this new a variable would not be affected by assignments to shared_stuff.a.

TL;DR: I think one solution could be to change createlaunchfile.py and anywhere else that's using from func.settings import args to from func import settings and changing any references from args to settings.args should resolve it and use the module's instance of the variable (with the parsed arguments) as we'd expect.

redromnon commented 1 year ago

Thanks a ton @afwolfe Will look at the probable solution for this. Did you also find out why this issue doesn't affect all users?

redromnon commented 1 year ago

This also explains why the bug doesn't pop in HeroicBashLauncher.py and listinstalled.py as from func import settings is being used.

afwolfe commented 1 year ago

No problem. It looks like around line 17 should be the timestamp.json not found. Looks like you haven't launched any game from Heroic at all. Please consider doing so." error. While it's not a great experience that users don't reach the Zenity dialog due to the bug, the HeroicBashLauncher.log should've contained it. Should the issue template be more explicit about requesting the log file? (I saw that it's mentioned in the linked section of the README.)

redromnon commented 1 year ago

HeroicBashLauncher must have contained it under HeroicBashLauncher.log. I'll make it a must to add the log file too.

redromnon commented 1 year ago

Made the changes and hopefully, it works fine. This is the updated build.