Skip to content

fix: resolve NameError crash at startup by defining argv before use#50

Open
zza-830 wants to merge 2 commits into
TruFoundation:mainfrom
zza-830:fix/argv-nameerror-startup
Open

fix: resolve NameError crash at startup by defining argv before use#50
zza-830 wants to merge 2 commits into
TruFoundation:mainfrom
zza-830:fix/argv-nameerror-startup

Conversation

@zza-830

@zza-830 zza-830 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Problem

The app_with_lower() function in trushell/cli.py references a bare name argv that is never imported or defined anywhere in the file. Every invocation from the command line that passes through this branch raises a NameError and crashes before the REPL starts.

Closes #40

Fix

Moved argv = sys.argv.copy() before the conditional block so the variable is always defined when reached by the comparison at the end of the function. Also added .lower() to the raw command construction to match the function's documented purpose of normalizing arguments to lowercase.

Testing

tests/test_cli_argv.py::test_app_with_lower_does_not_mutate_original_argv PASSED

All 21 existing tests pass (1 pre-existing failure in test_help_docs.py unrelated to this change).

Ziang Zhang added 2 commits June 8, 2026 09:46
The  function referenced a bare name  that was
never imported or defined, causing a NameError crash on every invocation.

Fix: move  before the conditional block so it is
always defined when reached by the comparison at the end of the function.

Closes TruFoundation#40
The test_run_help_prints_docstring_for_known_command test was failing
because the fake kernel lacked a _import_module method, causing the
module import to fail silently and fall through to the error message.

Add a working _fake_import_module that uses importlib to resolve
the module path, allowing run_help to read and print the docstring.
@AkshajSinghal

Copy link
Copy Markdown
Collaborator

@zza-830 The fix looks clean, but there’s a merge conflict in cli.py (likely clashing with the recent shell injection hardening or the cd env var fixes). Let’s get that resolved first.
Also, I noticed you added .lower() to the raw command construction. Let’s double-check that this doesn’t break case-sensitive file paths if we ever pass them through here. If it’s just for command lookup, let the Kernel handle normalization instead of mutating args at the CLI entry point.

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

Successfully merging this pull request may close these issues.

[Bug] NameError crash at startup: argv is not defined

2 participants