Skip to content

fix: prevent AttributeError crash when Llamafile model download fails#1734

Open
octo-patch wants to merge 1 commit intoopeninterpreter:mainfrom
octo-patch:fix/llamafile-null-model-path-crash
Open

fix: prevent AttributeError crash when Llamafile model download fails#1734
octo-patch wants to merge 1 commit intoopeninterpreter:mainfrom
octo-patch:fix/llamafile-null-model-path-crash

Conversation

@octo-patch
Copy link
Copy Markdown

Problem

When using interpreter --local and selecting the Llamafile provider, if download_model() fails (e.g. insufficient disk space, network error, or the user's machine can't fit any of the listed models), it returns None. The code then unconditionally executes:

model_name = model_path.split("/")[-1]

This crashes with AttributeError: 'NoneType' object has no attribute 'split' instead of displaying a clear, actionable error.

The bug affects two code paths in local_setup.py:

  1. No models existmodel_path = download_model(...) in the if not models: branch returns None
  2. Download new model — user selects "↓ Download new model" in the else branch; download_model() returns None; the if model_path: guard correctly skips the process launch, but execution still falls through to the crashing line

Solution

Add an early-return guard immediately before the Llamafile configuration block. When model_path is None, print a clear message and return the interpreter unchanged — instead of crashing.

if model_path is None:
    print(
        "\nNo model was downloaded. Cannot start Llamafile. "
        "Please try again or choose a different provider.\n"
    )
    return interpreter

Testing

  • Normal Llamafile flow (existing model or successful download) is unchanged — the guard only activates when model_path is None.
  • Simulated a failed download by having download_model() return None; previously crashed with AttributeError, now exits cleanly with a user-friendly message.

When download_model() returns None (due to insufficient disk space or a
network error), the subsequent model_path.split() call raises
AttributeError: 'NoneType' object has no attribute 'split'.

Add an early return after both the no-models and download-new-model
paths so the interpreter is returned cleanly with a clear message
instead of crashing.
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.

1 participant