{"record":{"id":"2b24ebdfdfd0f5d7","repo":"FoundationAgents/MetaGPT","slug":"create-device-path-folder-path-failed","errorCode":null,"errorMessage":"create device path: {folder_path} failed","messagePattern":"create device path: (.+?) failed","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"metagpt/environment/android/android_ext_env.py","lineNumber":149,"sourceCode":"\n    @property\n    def adb_prefix(self):\n        \"\"\"adb cmd prefix with `device_id`\"\"\"\n        return f\"adb -s {self.device_id} \"\n\n    def execute_adb_with_cmd(self, adb_cmd: str) -> str:\n        adb_cmd = adb_cmd.replace(\"\\\\\", \"/\")\n        res = subprocess.run(adb_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)\n        exec_res = ADB_EXEC_FAIL\n        if not res.returncode:\n            exec_res = res.stdout.strip()\n        return exec_res\n\n    def create_device_path(self, folder_path: Path):\n        adb_cmd = f\"{self.adb_prefix_shell} mkdir {folder_path} -p\"\n        res = self.execute_adb_with_cmd(adb_cmd)\n        if res == ADB_EXEC_FAIL:\n            raise RuntimeError(f\"create device path: {folder_path} failed\")\n\n    @property\n    def device_shape(self) -> tuple[int, int]:\n        adb_cmd = f\"{self.adb_prefix_shell} wm size\"\n        shape = (0, 0)\n        shape_res = self.execute_adb_with_cmd(adb_cmd)\n        if shape_res != ADB_EXEC_FAIL:\n            shape = tuple(map(int, shape_res.split(\": \")[1].split(\"x\")))\n        return shape\n\n    def list_devices(self):\n        adb_cmd = \"adb devices\"\n        res = self.execute_adb_with_cmd(adb_cmd)\n        devices = []\n        if res != ADB_EXEC_FAIL:\n            devices = res.split(\"\\n\")[1:]\n            devices = [device.split()[0] for device in devices]\n        return devices","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/environment/android/android_ext_env.py#L131-L167","documentation":"AndroidExtEnv.create_device_path runs `adb shell mkdir <folder> -p` through execute_adb_with_cmd, which returns the ADB_EXEC_FAIL sentinel when the subprocess exits non-zero. If the mkdir fails, the constructor raises RuntimeError 'create device path: {folder_path} failed', meaning the adb command itself could not run or was rejected by the device.","triggerScenarios":"Constructing AndroidExtEnv (it creates screenshot_dir and xml_dir on the device) when adb is not on PATH (subprocess returncode != 0), the device serial became stale between list_devices and mkdir, or the target path is on a read-only/unwritable volume.","commonSituations":"adb missing from PATH in a container/CI; device disconnected or emulator killed mid-init; shell quoting issues with the adb_prefix_shell string; running on Windows where the backslash replacement in execute_adb_with_cmd interacts badly with paths.","solutions":["Verify `adb shell mkdir <path> -p` succeeds manually on the target device; fix whatever it reports (PATH, permissions, stale connection).","Ensure adb is installed and resolvable from the Python process environment.","Reconnect/restart the device or emulator, then re-construct the environment.","If the default dirs are unwritable on your ROM, pass screenshot_dir/xml_dir values pointing to a writable location like /sdcard/... if the API allows overriding them."],"exampleFix":"# before\nenv = AndroidExtEnv(device_id=\"emulator-5554\")  # RuntimeError: create device path: ... failed\n\n# after\n# shell: verify manually first\n#   adb -s emulator-5554 shell mkdir /sdcard/metagpt/screenshot -p\n#   adb -s emulator-5554 shell mkdir /sdcard/metagpt/xml -p\nenv = AndroidExtEnv(device_id=\"emulator-5554\")","handlingStrategy":"try-catch","validationCode":"def adb_mkdir_ok(env, folder) -> bool:\n    return env.execute_adb_with_cmd(f\"{env.adb_prefix_shell} mkdir {folder} -p\") != ADB_EXEC_FAIL\n\n# probe before relying on construction to succeed:\nassert adb_mkdir_ok(env, env.screenshot_dir), f\"cannot create {env.screenshot_dir} on device\"","typeGuard":null,"tryCatchPattern":"try:\n    env = AndroidExtEnv(device_id=serial)\nexcept RuntimeError as e:\n    if \"create device path\" in str(e):\n        raise SystemExit(\"adb mkdir failed: check adb on PATH, device connected, and path writability\") from e\n    raise","preventionTips":["Pre-flight the exact adb command manually (`adb -s <serial> shell mkdir <dir> -p`) to confirm it returns 0.","Ensure adb is on PATH for the Python process, especially in CI containers.","Keep the device connection stable during construction — re-run if the emulator restarts mid-init."],"tags":["python","android","adb","filesystem","environment"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}