michael-n0813 / linux-idle-master

Linux version of idle-master, a simple script that emulates being in a steam game to unlock trading cards.
GNU General Public License v2.0
27 stars 8 forks source link

Feature request: Print stacktrace when ./start.py fails #22

Closed k4rli closed 5 months ago

k4rli commented 6 months ago

./start.py was failing for me and I added printing stacktrace to the line where it exited. Turned out issue was because it was trying to run python steam-idle.py internally and I didn't have python in PATH since I was running python3 main.py.

https://github.com/michael-n0813/linux-idle-master/blob/master/start.py#L69

Based on the log Error launching steam-idle with game ID.... I initially thought my cookie was invalid.

michael-n0813 commented 6 months ago

In regards to the feature request, I don't think the scrip is that complicated that it needs a debug option. Typically any undefined error will produce a stack trace and any defined error you can search and find the last called function before the exception.

In regards to the Python path issue, I think something simple like this could solve that

pyPath = "python"

try:
    subprocess.call(["python3", "--version"], stdout = subprocess.DEVNULL)
except:
    print("python3 not installed")
    input("Press Enter to continue...")
    sys.exit()

try:
    pyOut = subprocess.check_output(["python", "--version"])
    pyV3 = re.search("Python 3", str(pyOut))

    if not pyV3:
        pyPath = "python3"
        print("Python pointing to incorrect version, using Python3 instead")
except:
    pyPath = "python3"
    print("Python path error, using Python3 instead")

...

process_idle = subprocess.Popen([pyPath, "steam-idle.py", str(appID)])

...

What do you think. Would this be a good option?

michael-n0813 commented 5 months ago

Updated V2.2

cbe38942ee50a85362225d6b61e25de855671877

k4rli commented 5 months ago

Thanks, I didn't have time to check this issue previously but recent update seems nice.

This would also be a quick way to fix it

diff --git a/start.py b/start.py
index 71fe0f3..d596e2a 100644
--- a/start.py
+++ b/start.py
@@ -66,7 +66,7 @@ def idleOpen(appID):
         global idle_time

         idle_time = time.time()
-        process_idle = subprocess.Popen(["python", "steam-idle.py", str(appID)])
+        process_idle = subprocess.Popen([sys.executable, "steam-idle.py", str(appID)])
     except:
         logging.warning(Fore.RED + "Error launching steam-idle with game ID " + str(appID) + Fore.RESET)
         input("Press Enter to continue...")

sys.executable will be python3 if start.py is executed with python3 start.py, and it will also be python if python start.py is used.