Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
better error messages in js-sdk
0divc277f9f8a672
diff --git a/packages/js-sdk/src/sandbox/filesystem/index.ts b/packages/js-sdk/src/sandbox/filesystem/index.tsindex 7195b6bca..770d850ae 100644--- a/packages/js-sdk/src/sandbox/filesystem/index.ts+++ b/packages/js-sdk/src/sandbox/filesystem/index.ts@@ -147,8 +147,14 @@ export class Filesystem {dataOrOpts?: WriteData | FilesystemRequestOpts,opts?: FilesystemRequestOpts): Promise<EntryInfo | EntryInfo[]> {+ if (typeof pathOrFiles !== 'string' && !Array.isArray(pathOrFiles)) {+ throw new Error('Path or files are required')+ }+if (typeof pathOrFiles === 'string' && Array.isArray(dataOrOpts)) {- throw new Error('Cannot specify path with array of files')+ throw new Error(+ '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.'+ )}const { path, writeOpts, writeFiles } =@@ -160,6 +166,8 @@ export class Filesystem {}: { path: undefined, writeOpts: dataOrOpts as FilesystemRequestOpts, writeFiles: pathOrFiles as WriteEntry[] }+ if (writeFiles.length === 0) return [] as EntryInfo[]+const blobs = await Promise.all(writeFiles.map((f) => new Response(f.data).blob()))const res = await this.envdApi.api.POST('/files', {diff --git a/packages/js-sdk/tests/sandbox/files/write.test.ts b/packages/js-sdk/tests/sandbox/files/write.test.tsindex 51a7b968b..b2baa3b44 100644--- a/packages/js-sdk/tests/sandbox/files/write.test.ts+++ b/packages/js-sdk/tests/sandbox/files/write.test.ts@@ -17,7 +17,7 @@ sandboxTest('write file', async ({ sandbox }) => {}).catch((err) => {assert.instanceOf(err, Error)- assert.include(err.message, 'Cannot read properties of undefined')+ assert.include(err.message, 'Path or files are required')})const info = await sandbox.files.write(filename, content)@@ -47,7 +47,7 @@ sandboxTest('write multiple files', async ({ sandbox }) => {}).catch((err) => {assert.instanceOf(err, Error)- assert.include(err.message, 'Cannot read properties of undefined')+ assert.include(err.message, 'Path or files are required')})// Attempt to write with path and file array@@ -59,7 +59,10 @@ sandboxTest('write multiple files', async ({ sandbox }) => {}).catch((err) => {assert.instanceOf(err, Error)- assert.include(err.message, 'Cannot specify path with array of files')+ assert.include(+ err.message,+ '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.'+ )})// Attempt to write with one file in array