{"record":{"id":"acd974619b74b37a","repo":"crewAIInc/crewAI","slug":"an-unexpected-error-occurred-while-running-the-jso","errorCode":null,"errorMessage":"An unexpected error occurred while running the JSON crew: {e}","messagePattern":"An unexpected error occurred while running the JSON crew: (.+?)","errorType":"console","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"lib/cli/src/crewai_cli/run_crew.py","lineNumber":491,"sourceCode":"        env[CREWAI_TRAINED_AGENTS_FILE_ENV] = trained_agents_file\n    if crew_path is not None:\n        env[_CREWAI_JSON_CREW_DEFINITION_ENV] = str(crew_path)\n    if inputs is not None:\n        env[_CREWAI_JSON_CREW_INPUTS_ENV] = inputs\n\n    try:\n        subprocess.run(  # noqa: S603\n            command,\n            capture_output=False,\n            text=True,\n            check=True,\n            env=env,\n        )\n    except subprocess.CalledProcessError as e:\n        raise SystemExit(e.returncode) from e\n    except Exception as e:\n        click.echo(f\"An unexpected error occurred while running the JSON crew: {e}\")\n        raise SystemExit(1) from e\n\n    return None\n\n\ndef _chain_deploy() -> None:\n    from rich.console import Console\n\n    console = Console()\n\n    def print_system_exit_failure(exc: SystemExit) -> None:\n        if isinstance(exc.code, int):\n            detail = f\" with exit code {exc.code}\"\n        elif exc.code:\n            detail = f\": {exc.code}\"\n        else:\n            detail = \"\"\n        console.print(f\"\\nDeploy failed{detail}\\n\", style=\"bold red\")\n","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/cli/src/crewai_cli/run_crew.py#L473-L509","documentation":"Catch-all around the subprocess that runs a JSON crew (subprocess.run with check=True and a custom env). CalledProcessError is converted to the child's exit code first; this handler fires only for other exceptions — typically OSError/FileNotFoundError when the executable cannot spawn, or KeyboardInterrupt-adjacent failures. The message is echoed (note: to stdout, not err) and the process exits 1.","triggerScenarios":"The JSON-crew subprocess command references an interpreter/runner not present in env (FileNotFoundError); the constructed `env` dict is invalid (e.g. non-string values) raising TypeError or ValueError; a closed/stdin issue raising OSError.","commonSituations":"CI images lacking `uv`/`python` on PATH; env manipulation code injecting None or int values into os.environ copies; running with a stripped-down environment (env -i) that loses PATH.","solutions":["Read the exception text: 'No such file or directory' means the spawn executable is missing — install it or fix PATH.","Ensure the command runs in an environment where the interpreter/runner used for JSON crews is installed and on PATH.","If you pass a custom env to the CLI or wrap it, verify every variable is a string and PATH is preserved.","Since the message goes to stdout, check stdout (not stderr) when scraping CI logs for it."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import shutil\n\nrunner = \"uv\"  # executable the JSON-crew subprocess invokes\nif shutil.which(runner) is None:\n    raise SystemExit(f\"{runner} missing from PATH; install it before running JSON crews\")","typeGuard":null,"tryCatchPattern":"try:\n    run_json_crew(...)\nexcept SystemExit as e:\n    code = e.code\n    if code == 1 and spawned_ok is False:\n        # distinguish spawn failure (executable missing) from crew failure\n        logging.error(\"JSON crew subprocess failed to start; check PATH/uv\")\n    raise","preventionTips":["Verify uv/python availability in the container image before the run step.","Never replace PATH wholesale when constructing custom environments; copy os.environ and override selectively.","Scrape stdout as well as stderr in CI — this specific message is echoed to stdout."],"tags":["subprocess","json-crew","environment","cli"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}