adamrehn / ue4cli

Command-line interface for Unreal Engine 4
https://docs.adamrehn.com/ue4cli/
MIT License
249 stars 45 forks source link

`ue4 build-target` crashes when not specifying any target #66

Open sleeptightAnsiC opened 3 months ago

sleeptightAnsiC commented 3 months ago

Running ue4 build-target without giving any argument causes a crash:

╰─$ ue4 build-target
Traceback (most recent call last):
  File "/usr/bin/ue4", line 33, in <module>
    sys.exit(load_entry_point('ue4cli==0.0.54', 'console_scripts', 'ue4')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/ue4cli/cli.py", line 222, in main
    SUPPORTED_COMMANDS[command]['action'](manager, args)
  File "/usr/lib/python3.11/site-packages/ue4cli/cli.py", line 54, in <lambda>
    'action': lambda m, args: m.buildTarget(args.pop(0), args.pop(0) if (len(args) > 0) else 'Development', args),
                                            ^^^^^^^^^^^
IndexError: pop from empty list

~This is happening because some commands detect arguments with following condition: len(args) > 0 Said condition will always evaluate to True because Python always takes script directory as the first argument. We can easily change len(args) > 0 to len(args) > 1 and this should be resolved for most cases. However, when I was testing it, seems like not every function related to this issue would fail as I was expecting it, e.g. ue4 version works just fine, so it's worth investigating what's going on under the hood before fixing it.~

EDIT: No, I was wrong about it. The problem is super simple. We do args.pop(0) without checking if args contains anything which is clearly mentioned in callstack :D

Leaving this one for myself, should be quick to fix.

Reference: https://github.com/adamrehn/ue4cli/blob/fed71c1af4cffe3fed9358b08430068ad9454b77/ue4cli/cli.py#L52-L56

sleeptightAnsiC commented 3 months ago

~Blocked by https://github.com/adamrehn/ue4cli/pull/63 - This PR must be merged/rejected before attempting the fix, as it touches the same code and also uses len(args) > 0 condition in few places.~

sleeptightAnsiC commented 3 months ago

I was wrong...

Before passing args to the command, first arg is being already stripped here: https://github.com/adamrehn/ue4cli/blob/fed71c1af4cffe3fed9358b08430068ad9454b77/ue4cli/cli.py#L216-L218 I just randomly found a logical error for ue4 build-target

Editing the issue