crewAIInc/crewAI · error · SystemExit

An unexpected error occurred: {e}

Error message

An unexpected error occurred: {e}

What it means

A catch-all handler in the `crewai flow plot` CLI path that fires when subprocess.run() raises anything other than subprocess.CalledProcessError while plotting a flow. The message embeds the original exception text, and the CLI re-raises SystemExit(1) with the original exception as its cause. It almost always means the plotting command could not even be started (missing executable, bad environment) rather than that plotting itself failed.

Source

Thrown at lib/cli/src/crewai_cli/plot_flow.py:31

    )

    if definition := configured_project_declarative_flow():
        plot_declarative_flow_in_project_env(definition)
    else:
        command = ["uv", "run", "plot"]

        try:
            subprocess.run(  # noqa: S603
                command, capture_output=False, text=True, check=True
            )

        except subprocess.CalledProcessError as e:
            click.echo(f"An error occurred while plotting the flow: {e}", err=True)
            raise SystemExit(1) from e

        except Exception as e:
            click.echo(f"An unexpected error occurred: {e}", err=True)
            raise SystemExit(1) from e

View on GitHub (pinned to 754d7323be)

Solutions

  1. Read the exception text after the colon — FileNotFoundError means the executable is missing; install it (e.g. `pip install uv` or activate the right venv).
  2. Verify the full crewai package with plotting extras is installed: `pip install "crewai[tools]"`.
  3. Check the command can be run manually with the same PATH/cwd: reproduce the exact argv printed by running with `--verbose` if available.
  4. If the error came from inside the child (but exit code semantics were lost), run the plotting command directly in the shell to see the real traceback.

Example fix

# before (env without uv/python on PATH)
# $ crewai flow plot
# An unexpected error occurred: [Errno 2] No such file or directory: 'uv'

# after
# $ pip install uv  (or: use the venv's python)
# $ crewai flow plot
Defensive patterns

Strategy: try-catch

Validate before calling

import shutil

runner = "uv"  # or whatever the plotting subprocess invokes
if shutil.which(runner) is None:
    raise SystemExit(f"{runner} not on PATH; install it before plotting")

Try / catch

try:
    plot_flow(...)  # or subprocess.run(plot_cmd, check=True)
except SystemExit:
    raise
except (OSError, FileNotFoundError) as e:
    # spawn failure: missing executable / bad env
    logging.error("plot subprocess could not start: %s", e)
    raise

Prevention

When it happens

Trigger: Running `crewai flow plot` when the subprocess executable (e.g. `uv` or `python`) is not on PATH raises FileNotFoundError; an invalid cwd or closed file descriptors raise OSError. Any non-CalledProcessError from subprocess.run lands here. CalledProcessError is handled separately at plot_flow.py:26-29.

Common situations: Installing only crewai-cli (not the full crewai package) in a slim container/CI image where `uv` is absent; a virtualenv that was recreated without the plotting dependency (crewai[tools]); PATH clobbered by a Makefile or CI step; permission errors on the project directory.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/ec04b22199f63a0a. Report an issue: GitHub.