Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Add typed not-found errors for volumes (#1730)
devin-ai-integration[bot]05aa03c35cf1
diff --git a/.changeset/volume-not-found-error.md b/.changeset/volume-not-found-error.mdnew file mode 100644index 000000000..ab55e7efc--- /dev/null+++ b/.changeset/volume-not-found-error.md@@ -0,0 +1,6 @@+---+'e2b': patch+'@e2b/python-sdk': patch+---++Add typed not-found errors for volumes: `VolumeNotFoundError` / `VolumeNotFoundException` (thrown when a volume is not found) and `VolumePathNotFoundError` / `VolumePathNotFoundException` (thrown when a path inside a volume is not found). All subclass the existing `NotFoundError` / `NotFoundException`, so existing catches keep working.diff --git a/packages/js-sdk/src/errors.ts b/packages/js-sdk/src/errors.tsindex e66ea07c6..561920ca7 100644--- a/packages/js-sdk/src/errors.ts+++ b/packages/js-sdk/src/errors.ts@@ -174,3 +174,23 @@ export class VolumeError extends Error {this.name = 'VolumeError'}}++/**+ * Thrown when a volume is not found.+ */+export class VolumeNotFoundError extends NotFoundError {+ constructor(message: string, stackTrace?: string) {+ super(message, stackTrace)+ this.name = 'VolumeNotFoundError'+ }+}++/**+ * Thrown when a file or directory is not found inside a volume.+ */+export class VolumePathNotFoundError extends NotFoundError {+ constructor(message: string, stackTrace?: string) {+ super(message, stackTrace)+ this.name = 'VolumePathNotFoundError'+ }+}diff --git a/packages/js-sdk/src/index.ts b/packages/js-sdk/src/index.tsindex b67c07c08..4c8ec4ad0 100644--- a/packages/js-sdk/src/index.ts+++ b/packages/js-sdk/src/index.ts@@ -23,6 +23,8 @@ export {BuildError,FileUploadError,VolumeError,+ VolumeNotFoundError,+ VolumePathNotFoundError,} from './errors'export type { Logger } from './logs'diff --git a/packages/js-sdk/src/volume/index.ts b/packages/js-sdk/src/volume/index.tsindex 87a6803b5..c3c54b508 100644--- a/packages/js-sdk/src/volume/index.ts+++ b/packages/js-sdk/src/volume/index.ts@@ -13,7 +13,12 @@ import {wrapStreamWithConnectionCleanup,} from '../connectionConfig'import { isArrayBufferLike, isBlobLike } from '../is'-import { NotFoundError, VolumeError } from '../errors'+import {+ NotFoundError,+ VolumeError,+ VolumeNotFoundError,+ VolumePathNotFoundError,+} from '../errors'import { toUploadBody } from '../utils'import { VolumeFileType } from './types'import type {@@ -190,7 +195,7 @@ export class Volume {})if (res.response.status === 404) {- throw new NotFoundError(`Volume ${volumeId} not found`)+ throw new VolumeNotFoundError(`Volume ${volumeId} not found`)}const err = handleApiError(res, VolumeError)@@ -296,7 +301,7 @@ export class Volume {})if (res.response.status === 404) {- throw new NotFoundError(`Path ${path} not found`)+ throw new VolumePathNotFoundError(`Path ${path} not found`)}const err = handleApiError(res, VolumeError)@@ -340,7 +345,7 @@ export class Volume {})if (res.response.status === 404) {- throw new NotFoundError(`Path ${path} not found`)+ throw new VolumePathNotFoundError(`Path ${path} not found`)}const err = handleApiError(res, VolumeError)@@ -382,7 +387,7 @@ export class Volume {})if (res.response.status === 404) {- throw new NotFoundError(`Path ${path} not found`)+ throw new VolumePathNotFoundError(`Path ${path} not found`)}const err = handleApiError(res, VolumeError)@@ -457,7 +462,7 @@ export class Volume {})if (res.response.status === 404) {- throw new NotFoundError(`Path ${path} not found`)+ throw new VolumePathNotFoundError(`Path ${path} not found`)}const err = handleApiError(res, VolumeError)@@ -574,7 +579,7 @@ export class Volume {await res.response.body.cancel().catch(() => {})}cleanup()- throw new NotFoundError(`Path ${path} not found`)+ throw new VolumePathNotFoundError(`Path ${path} not found`)}const err = handleApiError(res, VolumeError)@@ -615,7 +620,7 @@ export class Volume {})if (res.response.status === 404) {- throw new NotFoundError(`Path ${path} not found`)+ throw new VolumePathNotFoundError(`Path ${path} not found`)}const err = handleApiError(res, VolumeError)@@ -697,7 +702,7 @@ export class Volume {})if (res.response.status === 404) {- throw new NotFoundError(`Path ${path} not found`)+ throw new VolumePathNotFoundError(`Path ${path} not found`)}const err = handleApiError(res, VolumeError)@@ -737,7 +742,7 @@ export class Volume {})if (res.response.status === 404) {- throw new NotFoundError(`Path ${path} not found`)+ throw new VolumePathNotFoundError(`Path ${path} not found`)}const err = handleApiError(res, VolumeError)diff --git a/packages/js-sdk/tests/volume/volume.test.ts b/packages/js-sdk/tests/volume/volume.test.tsindex 8e6082480..d0b921a2c 100644--- a/packages/js-sdk/tests/volume/volume.test.ts+++ b/packages/js-sdk/tests/volume/volume.test.ts@@ -3,7 +3,13 @@ import { http, HttpResponse } from 'msw'import { setupServer } from 'msw/node'import { randomUUID } from 'node:crypto'-import { Volume, NotFoundError, VolumeError } from '../../src'+import {+ Volume,+ NotFoundError,+ VolumeError,+ VolumeNotFoundError,+ VolumePathNotFoundError,+} from '../../src'import { VolumeConnectionConfig } from '../../src/volume/client'import { runtime } from '../../src/utils'import { apiUrl } from '../setup'@@ -140,10 +146,10 @@ describe('Volume CRUD', () => {expect(result).toBe(false)})- it('should throw NotFoundError when getting info of non-existent volume', async () => {- await expect(Volume.getInfo('non-existent-id')).rejects.toThrow(- NotFoundError- )+ it('should throw VolumeNotFoundError when getting info of non-existent volume', async () => {+ const err = await Volume.getInfo('non-existent-id').catch((err) => err)+ expect(err).toBeInstanceOf(VolumeNotFoundError)+ expect(err).toBeInstanceOf(NotFoundError)})it('should throw VolumeError for a non-2xx response without content', async () => {@@ -324,10 +330,12 @@ describe('Volume content readFile', () => {expect(await new Response(stream).text()).toBe('')})- it('should throw NotFoundError for a missing file', async () => {+ it('should throw VolumePathNotFoundError for a missing file', async () => {const vol = await Volume.create('content-volume')- await expect(vol.readFile('missing.txt')).rejects.toThrow(NotFoundError)+ const err = await vol.readFile('missing.txt').catch((err) => err)+ expect(err).toBeInstanceOf(VolumePathNotFoundError)+ expect(err).toBeInstanceOf(NotFoundError)})it('should reject at call time for a missing file with stream format', async () => {@@ -335,7 +343,7 @@ describe('Volume content readFile', () => {await expect(vol.readFile('missing.txt', { format: 'stream' })- ).rejects.toThrow(NotFoundError)+ ).rejects.toThrow(VolumePathNotFoundError)})})diff --git a/packages/python-sdk/e2b/__init__.py b/packages/python-sdk/e2b/__init__.pyindex 3a152f15f..62e589b0a 100644--- a/packages/python-sdk/e2b/__init__.py+++ b/packages/python-sdk/e2b/__init__.py@@ -52,6 +52,8 @@ from .exceptions import (TemplateException,TimeoutException,VolumeException,+ VolumeNotFoundException,+ VolumePathNotFoundException,)from .sandbox.commands.command_handle import (CommandExitException,@@ -174,6 +176,8 @@ __all__ = ["FileUploadException","RateLimitException","VolumeException",+ "VolumeNotFoundException",+ "VolumePathNotFoundException",# Sandbox API"SandboxInfo","SandboxInfoLifecycle",diff --git a/packages/python-sdk/e2b/exceptions.py b/packages/python-sdk/e2b/exceptions.pyindex c7ed37149..b3626e1e5 100644--- a/packages/python-sdk/e2b/exceptions.py+++ b/packages/python-sdk/e2b/exceptions.py@@ -131,3 +131,15 @@ class VolumeException(Exception):Raised when general volume errors occur."""+++class VolumeNotFoundException(NotFoundException):+ """+ Raised when a volume is not found.+ """+++class VolumePathNotFoundException(NotFoundException):+ """+ Raised when a file or directory is not found inside a volume.+ """diff --git a/packages/python-sdk/e2b/volume/volume_async.py b/packages/python-sdk/e2b/volume/volume_async.pyindex 7b7c7b62b..03bee8b0e 100644--- a/packages/python-sdk/e2b/volume/volume_async.py+++ b/packages/python-sdk/e2b/volume/volume_async.py@@ -21,7 +21,12 @@ from e2b.api.client.models import (from e2b.api.client.types import Responsefrom e2b.api.client_async import get_api_client as get_core_api_clientfrom e2b.connection_config import ApiParams, ConnectionConfig, ProxyTypes-from e2b.exceptions import NotFoundException, VolumeException+from e2b.exceptions import (+ NotFoundException,+ VolumeException,+ VolumeNotFoundException,+ VolumePathNotFoundException,+)from e2b.volume.client.api.volumes import (get_volumecontent_volume_id_path as get_path,get_volumecontent_volume_id_dir as get_dir,@@ -183,7 +188,7 @@ class AsyncVolume:)if res.status_code == 404:- raise NotFoundException(f"Volume {volume_id} not found")+ raise VolumeNotFoundException(f"Volume {volume_id} not found")if res.status_code >= 300:raise handle_api_exception(res, VolumeException)@@ -277,7 +282,7 @@ class AsyncVolume:)if res.status_code == 404:- raise NotFoundException(f"Path {path} not found")+ raise VolumePathNotFoundException(f"Path {path} not found")if res.status_code >= 300:raise handle_api_exception(res, VolumeException)@@ -329,7 +334,7 @@ class AsyncVolume:)if res.status_code == 404:- raise NotFoundException(f"Path {path} not found")+ raise VolumePathNotFoundException(f"Path {path} not found")if res.status_code >= 300:raise handle_api_exception(res, VolumeException)@@ -381,7 +386,7 @@ class AsyncVolume:)if res.status_code == 404:- raise NotFoundException(f"Path {path} not found")+ raise VolumePathNotFoundException(f"Path {path} not found")if res.status_code >= 300:raise handle_api_exception(res, VolumeException)@@ -433,7 +438,7 @@ class AsyncVolume:)if res.status_code == 404:- raise NotFoundException(f"Path {path} not found")+ raise VolumePathNotFoundException(f"Path {path} not found")if res.status_code >= 300:raise handle_api_exception(res, VolumeException)@@ -542,7 +547,7 @@ class AsyncVolume:response = await read_bounded(stream_cm.__aenter__())try:if response.status_code == 404:- raise NotFoundException(f"Path {path} not found")+ raise VolumePathNotFoundException(f"Path {path} not found")if response.status_code >= 300:api_response = Response(@@ -575,7 +580,7 @@ class AsyncVolume:)if response.status_code == 404:- raise NotFoundException(f"Path {path} not found")+ raise VolumePathNotFoundException(f"Path {path} not found")if response.status_code >= 300:api_response = Response(@@ -649,7 +654,7 @@ class AsyncVolume:)if res.status_code == 404:- raise NotFoundException(f"Path {path} not found")+ raise VolumePathNotFoundException(f"Path {path} not found")if res.status_code >= 300:raise handle_api_exception(res, VolumeException)@@ -683,7 +688,7 @@ class AsyncVolume:)if res.status_code == 404:- raise NotFoundException(f"Path {path} not found")+ raise VolumePathNotFoundException(f"Path {path} not found")if res.status_code >= 300:raise handle_api_exception(res, VolumeException)diff --git a/packages/python-sdk/e2b/volume/volume_sync.py b/packages/python-sdk/e2b/volume/volume_sync.pyindex 4415838fe..b9dad9d51 100644--- a/packages/python-sdk/e2b/volume/volume_sync.py+++ b/packages/python-sdk/e2b/volume/volume_sync.py@@ -20,7 +20,12 @@ from e2b.api.client.models import (from e2b.api.client.types import Responsefrom e2b.api.client_sync import get_api_client as get_core_api_clientfrom e2b.connection_config import ApiParams, ConnectionConfig, ProxyTypes-from e2b.exceptions import NotFoundException, VolumeException+from e2b.exceptions import (+ NotFoundException,+ VolumeException,+ VolumeNotFoundException,+ VolumePathNotFoundException,+)from e2b.volume.client.api.volumes import (get_volumecontent_volume_id_path as get_path,get_volumecontent_volume_id_dir as get_dir,@@ -180,7 +185,7 @@ class Volume:)if res.status_code == 404:- raise NotFoundException(f"Volume {volume_id} not found")+ raise VolumeNotFoundException(f"Volume {volume_id} not found")if res.status_code >= 300:raise handle_api_exception(res, VolumeException)@@ -274,7 +279,7 @@ class Volume:)if res.status_code == 404:- raise NotFoundException(f"Path {path} not found")+ raise VolumePathNotFoundException(f"Path {path} not found")if res.status_code >= 300:raise handle_api_exception(res, VolumeException)@@ -326,7 +331,7 @@ class Volume:)if res.status_code == 404:- raise NotFoundException(f"Path {path} not found")+ raise VolumePathNotFoundException(f"Path {path} not found")if res.status_code >= 300:raise handle_api_exception(res, VolumeException)@@ -378,7 +383,7 @@ class Volume:)if res.status_code == 404:- raise NotFoundException(f"Path {path} not found")+ raise VolumePathNotFoundException(f"Path {path} not found")if res.status_code >= 300:raise handle_api_exception(res, VolumeException)@@ -430,7 +435,7 @@ class Volume:)if res.status_code == 404:- raise NotFoundException(f"Path {path} not found")+ raise VolumePathNotFoundException(f"Path {path} not found")if res.status_code >= 300:raise handle_api_exception(res, VolumeException)@@ -520,7 +525,7 @@ class Volume:timeout=stream_timeout,) as response:if response.status_code == 404:- raise NotFoundException(f"Path {path} not found")+ raise VolumePathNotFoundException(f"Path {path} not found")if response.status_code >= 300:api_response = Response(@@ -543,7 +548,7 @@ class Volume:)if response.status_code == 404:- raise NotFoundException(f"Path {path} not found")+ raise VolumePathNotFoundException(f"Path {path} not found")if response.status_code >= 300:api_response = Response(@@ -619,7 +624,7 @@ class Volume:)if res.status_code == 404:- raise NotFoundException(f"Path {path} not found")+ raise VolumePathNotFoundException(f"Path {path} not found")if res.status_code >= 300:raise handle_api_exception(res, VolumeException)@@ -653,7 +658,7 @@ class Volume:)if res.status_code == 404:- raise NotFoundException(f"Path {path} not found")+ raise VolumePathNotFoundException(f"Path {path} not found")if res.status_code >= 300:raise handle_api_exception(res, VolumeException)diff --git a/packages/python-sdk/tests/async/volume_async/test_volume.py b/packages/python-sdk/tests/async/volume_async/test_volume.pyindex b63577702..317beab72 100644--- a/packages/python-sdk/tests/async/volume_async/test_volume.py+++ b/packages/python-sdk/tests/async/volume_async/test_volume.py@@ -5,7 +5,7 @@ import pytestfrom e2b import AsyncVolumefrom e2b.connection_config import ConnectionConfig-from e2b.exceptions import NotFoundException+from e2b.exceptions import NotFoundException, VolumeNotFoundExceptionfrom e2b.api.client.models.volume_and_token import VolumeAndTokenfrom e2b.api.client.types import Responseimport e2b.api.client.api.volumes.post_volumes as post_volumes_mod@@ -130,8 +130,9 @@ async def test_destroy_nonexistent_volume():async def test_get_info_nonexistent_volume():- with pytest.raises(NotFoundException):+ with pytest.raises(VolumeNotFoundException) as exc_info:await AsyncVolume.get_info("non-existent-id")+ assert isinstance(exc_info.value, NotFoundException)async def test_create_volume_keeps_proxy_for_content_calls():diff --git a/packages/python-sdk/tests/async/volume_async/test_volume_content.py b/packages/python-sdk/tests/async/volume_async/test_volume_content.pyindex 3c6aa64e1..41d30b083 100644--- a/packages/python-sdk/tests/async/volume_async/test_volume_content.py+++ b/packages/python-sdk/tests/async/volume_async/test_volume_content.py@@ -2,7 +2,7 @@ import httpximport pytestfrom e2b import AsyncVolume-from e2b.exceptions import NotFoundException+from e2b.exceptions import VolumePathNotFoundExceptionimport e2b.volume.volume_async as volume_async_mod_files = {@@ -50,7 +50,7 @@ async def test_read_file_stream_yields_content(volume: AsyncVolume):async def test_read_file_stream_raises_for_missing_path(volume: AsyncVolume):- with pytest.raises(NotFoundException):+ with pytest.raises(VolumePathNotFoundException):async for _ in await volume.read_file("missing.txt", format="stream"):pass@@ -72,5 +72,5 @@ async def test_read_file_text_and_bytes_of_empty_file(volume: AsyncVolume):async def test_read_file_missing_path_raises(volume: AsyncVolume):- with pytest.raises(NotFoundException):+ with pytest.raises(VolumePathNotFoundException):await volume.read_file("missing.txt")diff --git a/packages/python-sdk/tests/sync/volume_sync/test_volume.py b/packages/python-sdk/tests/sync/volume_sync/test_volume.pyindex ea4202a0e..453eb9041 100644--- a/packages/python-sdk/tests/sync/volume_sync/test_volume.py+++ b/packages/python-sdk/tests/sync/volume_sync/test_volume.py@@ -5,7 +5,7 @@ import pytestfrom e2b import Volumefrom e2b.connection_config import ConnectionConfig-from e2b.exceptions import NotFoundException+from e2b.exceptions import NotFoundException, VolumeNotFoundExceptionfrom e2b.api.client.models.volume_and_token import VolumeAndTokenfrom e2b.api.client.types import Responseimport e2b.api.client.api.volumes.post_volumes as post_volumes_mod@@ -130,8 +130,9 @@ def test_destroy_nonexistent_volume():def test_get_info_nonexistent_volume():- with pytest.raises(NotFoundException):+ with pytest.raises(VolumeNotFoundException) as exc_info:Volume.get_info("non-existent-id")+ assert isinstance(exc_info.value, NotFoundException)def test_create_volume_keeps_proxy_for_content_calls():diff --git a/packages/python-sdk/tests/sync/volume_sync/test_volume_content.py b/packages/python-sdk/tests/sync/volume_sync/test_volume_content.pyindex ba11709ef..1368db512 100644--- a/packages/python-sdk/tests/sync/volume_sync/test_volume_content.py+++ b/packages/python-sdk/tests/sync/volume_sync/test_volume_content.py@@ -2,7 +2,7 @@ import httpximport pytestfrom e2b import Volume-from e2b.exceptions import NotFoundException+from e2b.exceptions import VolumePathNotFoundExceptionimport e2b.volume.volume_sync as volume_sync_mod_files = {@@ -47,7 +47,7 @@ def test_read_file_stream_yields_content(volume: Volume):def test_read_file_stream_raises_for_missing_path(volume: Volume):- with pytest.raises(NotFoundException):+ with pytest.raises(VolumePathNotFoundException):for _ in volume.read_file("missing.txt", format="stream"):pass@@ -68,5 +68,5 @@ def test_read_file_text_and_bytes_of_empty_file(volume: Volume):def test_read_file_missing_path_raises(volume: Volume):- with pytest.raises(NotFoundException):+ with pytest.raises(VolumePathNotFoundException):volume.read_file("missing.txt")