{"record":{"id":"ec04b22199f63a0a","repo":"crewAIInc/crewAI","slug":"an-unexpected-error-occurred-e","errorCode":null,"errorMessage":"An unexpected error occurred: {e}","messagePattern":"An unexpected error occurred: (.+?)","errorType":"console","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"lib/cli/src/crewai_cli/plot_flow.py","lineNumber":31,"sourceCode":"    )\n\n    if definition := configured_project_declarative_flow():\n        plot_declarative_flow_in_project_env(definition)\n    else:\n        command = [\"uv\", \"run\", \"plot\"]\n\n        try:\n            subprocess.run(  # noqa: S603\n                command, capture_output=False, text=True, check=True\n            )\n\n        except subprocess.CalledProcessError as e:\n            click.echo(f\"An error occurred while plotting the flow: {e}\", err=True)\n            raise SystemExit(1) from e\n\n        except Exception as e:\n            click.echo(f\"An unexpected error occurred: {e}\", err=True)\n            raise SystemExit(1) from e\n","sourceCodeStart":13,"sourceCodeEnd":32,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/cli/src/crewai_cli/plot_flow.py#L13-L32","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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).","Verify the full crewai package with plotting extras is installed: `pip install \"crewai[tools]\"`.","Check the command can be run manually with the same PATH/cwd: reproduce the exact argv printed by running with `--verbose` if available.","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."],"exampleFix":"# before (env without uv/python on PATH)\n# $ crewai flow plot\n# An unexpected error occurred: [Errno 2] No such file or directory: 'uv'\n\n# after\n# $ pip install uv  (or: use the venv's python)\n# $ crewai flow plot","handlingStrategy":"try-catch","validationCode":"import shutil\n\nrunner = \"uv\"  # or whatever the plotting subprocess invokes\nif shutil.which(runner) is None:\n    raise SystemExit(f\"{runner} not on PATH; install it before plotting\")","typeGuard":null,"tryCatchPattern":"try:\n    plot_flow(...)  # or subprocess.run(plot_cmd, check=True)\nexcept SystemExit:\n    raise\nexcept (OSError, FileNotFoundError) as e:\n    # spawn failure: missing executable / bad env\n    logging.error(\"plot subprocess could not start: %s\", e)\n    raise","preventionTips":["Pin and verify the plotting runtime (uv/python + crewai[tools]) in the environment before invoking `crewai flow plot`.","In CI, add a preflight step `crewai --version` and `uv --version` to fail with a clear message.","Keep PATH intact when wrapping the CLI in scripts or containers."],"tags":["subprocess","plotting","flow","cli","environment"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}