Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

better error messages in python-sdk

0div2956a6e7b92f
diff --git a/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
index f9ede3c29..720b7c74d 100644
--- a/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
+++ b/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
@@ -159,10 +159,12 @@ class Filesystem:
path, write_files, user, request_timeout = None, [], "user", None
if isinstance(path_or_files, str):
if isinstance(data_or_user, list):
- raise Exception("Cannot specify path with array of files")
+ raise Exception("Cannot specify both path and array of files. You have to specify either path and data for a single file or an array for multiple files.")
path, write_files, user, request_timeout = \
path_or_files, [{"path": path_or_files, "data": data_or_user}], user_or_request_timeout or "user", request_timeout_or_none
else:
+ if path_or_files is None:
+ raise Exception("Path or files are required")
path, write_files, user, request_timeout = \
None, path_or_files, data_or_user, user_or_request_timeout
diff --git a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
index 94b7e144d..015d9e8c2 100644
--- a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
+++ b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
@@ -133,7 +133,10 @@ class Filesystem:
request_timeout: Optional[float] = None,
) -> List[EntryInfo]:
"""
- Writes multiple files.
+ Writes a list of files to the filesystem.
+ When writing to a file that doesn't exist, the file will get created.
+ When writing to a file that already exists, the file will get overwritten.
+ When writing to a file that's in a directory that doesn't exist, you'll get an error.
:param files: list of files to write
:param user: Run the operation as this user
@@ -148,20 +151,15 @@ class Filesystem:
user_or_request_timeout: Optional[float | Username] = None,
request_timeout_or_none: Optional[float] = None
) -> EntryInfo | List[EntryInfo]:
- """
- Writes content to a file on the path.
- When writing to a file that doesn't exist, the file will get created.
- When writing to a file that already exists, the file will get overwritten.
- When writing to a file that's in a directory that doesn't exist, you'll get an error.
- """
-
path, write_files, user, request_timeout = None, [], "user", None
if isinstance(path_or_files, str):
if isinstance(data_or_user, list):
- raise Exception("Cannot specify path with array of files")
+ raise Exception("Cannot specify both path and array of files. You have to specify either path and data for a single file or an array for multiple files.")
path, write_files, user, request_timeout = \
path_or_files, [{"path": path_or_files, "data": data_or_user}], user_or_request_timeout or "user", request_timeout_or_none
else:
+ if path_or_files is None:
+ raise Exception("Path or files are required")
path, write_files, user, request_timeout = \
None, path_or_files, data_or_user, user_or_request_timeout
diff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_write.py b/packages/python-sdk/tests/async/sandbox_async/files/test_write.py
index 8d388a93d..b897f3673 100644
--- a/packages/python-sdk/tests/async/sandbox_async/files/test_write.py
+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_write.py
@@ -9,7 +9,7 @@ async def test_write_file(async_sandbox: AsyncSandbox):
try:
await async_sandbox.files.write(None, content)
except Exception as e:
- assert "object is not iterable" in str(e)
+ assert "Path or files are required" in str(e)
info = await async_sandbox.files.write(filename, content)
assert info.path == f"/home/user/{filename}"
@@ -30,13 +30,13 @@ async def test_write_multiple_files(async_sandbox: AsyncSandbox):
try:
await async_sandbox.files.write(None, [])
except Exception as e:
- assert "object is not iterable" in str(e)
+ assert "Path or files are required" in str(e)
# Attempt to write with path and file array
try:
await async_sandbox.files.write("/path/to/file", [{ "path": "one_test_file.txt", "data": "This is a test file." }])
except Exception as e:
- assert "Cannot specify path with array of files" in str(e)
+ assert "Cannot specify both path and array of files. You have to specify either path and data for a single file or an array for multiple files." in str(e)
# Attempt to write with one file in array
info = await async_sandbox.files.write([{ "path": "one_test_file.txt", "data": "This is a test file." }])
diff --git a/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.py
index 0a97b542b..5a3638765 100644
--- a/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.py
+++ b/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.py
@@ -8,7 +8,7 @@ def test_write_file(sandbox):
try:
sandbox.files.write(None, content)
except Exception as e:
- assert "object is not iterable" in str(e)
+ assert "Path or files are required" in str(e)
info = sandbox.files.write(filename, content)
assert info.path == f"/home/user/{filename}"
@@ -29,13 +29,13 @@ def test_write_multiple_files(sandbox):
try:
sandbox.files.write(None, [])
except Exception as e:
- assert "object is not iterable" in str(e)
+ assert "Path or files are required" in str(e)
# Attempt to write with path and file array
try:
sandbox.files.write("/path/to/file", [{ "path": "one_test_file.txt", "data": "This is a test file." }])
except Exception as e:
- assert "Cannot specify path with array of files" in str(e)
+ assert "Cannot specify both path and array of files. You have to specify either path and data for a single file or an array for multiple files." in str(e)
# Attempt to write with one file in array
info = sandbox.files.write([{ "path": "one_test_file.txt", "data": "This is a test file." }])