| 96 | |
| 97 | |
| 98 | async def test_exec_error(client: dagger.Client, httpx_mock: HTTPXMock): |
| 99 | error = { |
| 100 | "message": "command not found", |
| 101 | "path": ["container", "from", "withExec"], |
| 102 | "locations": [{"line": 3, "column": 5}], |
| 103 | "extensions": { |
| 104 | "_type": "EXEC_ERROR", |
| 105 | "cmd": ["sh", "-c", "spam"], |
| 106 | "exitCode": 127, |
| 107 | "stdout": "", |
| 108 | "stderr": "/bin/sh: spam: not found", |
| 109 | }, |
| 110 | } |
| 111 | httpx_mock.add_response(json={"errors": [error]}) |
| 112 | ctr = client.container().from_("alpine").with_exec(["sh", "-c", "spam"]) |
| 113 | |
| 114 | with pytest.raises(dagger.ExecError) as exc_info: |
| 115 | await ctr |
| 116 | |
| 117 | exc = exc_info.value |
| 118 | assert issubclass(exc.__class__, dagger.QueryError) |
| 119 | |
| 120 | assert exc.message == "command not found" |
| 121 | assert exc.command == ["sh", "-c", "spam"] |
| 122 | assert exc.exit_code == 127 |
| 123 | assert exc.stderr == "/bin/sh: spam: not found" |
| 124 | assert exc.stdout == "" |
| 125 | |
| 126 | assert "command not found" in str(exc) |