Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sleeptightAnsiC opened this issue Mar 23, 2024 · 2 comments
Open

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

sleeptightAnsiC opened this issue Mar 23, 2024 · 2 comments

Comments

@sleeptightAnsiC
Copy link
Contributor

sleeptightAnsiC commented Mar 23, 2024

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:

ue4cli/ue4cli/cli.py

Lines 52 to 56 in fed71c1

'build-target': {
'description': 'Build the specified target using UBT',
'action': lambda m, args: m.buildTarget(args.pop(0), args.pop(0) if (len(args) > 0) else 'Development', args),
'args': '<TARGET> [CONFIGURATION]'
},

@sleeptightAnsiC
Copy link
Contributor Author

sleeptightAnsiC commented Mar 23, 2024

Blocked by #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
Copy link
Contributor Author

sleeptightAnsiC commented Mar 23, 2024

I was wrong...

Before passing args to the command, first arg is being already stripped here:

ue4cli/ue4cli/cli.py

Lines 216 to 218 in fed71c1

# Extract the specified command and any trailing arguments
command = 'help' if len(sys.argv) < 2 else sys.argv[1].strip('-')
args = sys.argv[2:]

I just randomly found a logical error for ue4 build-target

Editing the issue

@sleeptightAnsiC sleeptightAnsiC changed the title cli.py SUPPORTED_COMMANDS (len(args) > 0) always evaluates to True ue4 build-target crashes when not specifying any target Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant