Skip to content

armgit / E2B

Public Imported from GitHub
0

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

refactor(js-sdk): drop unused stackTrace params from error constructors (#1732)

devin-ai-integration[bot]d79c6cd9735f
diff --git a/.changeset/plenty-cases-repeat.md b/.changeset/plenty-cases-repeat.md
new file mode 100644
index 000000000..af1fbcabc
--- /dev/null
+++ b/.changeset/plenty-cases-repeat.md
@@ -0,0 +1,5 @@
+---
+'e2b': patch
+---
+
+Remove the unused `stackTrace` constructor parameter from error classes that never have a caller stack trace attached (`TimeoutError`, `NotEnoughSpaceError`, `NotFoundError`, `FileNotFoundError`, `SandboxNotFoundError`, `GitUpstreamError`, `VolumeNotFoundError`, `VolumePathNotFoundError`).
diff --git a/packages/js-sdk/src/errors.ts b/packages/js-sdk/src/errors.ts
index 561920ca7..b1e71382b 100644
--- a/packages/js-sdk/src/errors.ts
+++ b/packages/js-sdk/src/errors.ts
@@ -11,12 +11,9 @@ export function formatSandboxTimeoutError(message: string) {
* Thrown when general sandbox errors occur.
*/
export class SandboxError extends Error {
- constructor(message?: string, stackTrace?: string) {
+ constructor(message?: string) {
super(message)
this.name = 'SandboxError'
- if (stackTrace) {
- this.stack = stackTrace
- }
}
}
@@ -32,8 +29,8 @@ export class SandboxError extends Error {
* The [unknown] error type is sometimes caused by the sandbox timeout when the request is not processed correctly.
*/
export class TimeoutError extends SandboxError {
- constructor(message: string, stackTrace?: string) {
- super(message, stackTrace)
+ constructor(message: string) {
+ super(message)
this.name = 'TimeoutError'
}
}
@@ -43,8 +40,11 @@ export class TimeoutError extends SandboxError {
*/
export class InvalidArgumentError extends SandboxError {
constructor(message: string, stackTrace?: string) {
- super(message, stackTrace)
+ super(message)
this.name = 'InvalidArgumentError'
+ if (stackTrace) {
+ this.stack = stackTrace
+ }
}
}
@@ -52,8 +52,8 @@ export class InvalidArgumentError extends SandboxError {
* Thrown when there is not enough disk space.
*/
export class NotEnoughSpaceError extends SandboxError {
- constructor(message: string, stackTrace?: string) {
- super(message, stackTrace)
+ constructor(message: string) {
+ super(message)
this.name = 'NotEnoughSpaceError'
}
}
@@ -64,8 +64,8 @@ export class NotEnoughSpaceError extends SandboxError {
* @deprecated Use {@link FileNotFoundError} or {@link SandboxNotFoundError} instead. This class will be removed in the next major version.
*/
export class NotFoundError extends SandboxError {
- constructor(message: string, stackTrace?: string) {
- super(message, stackTrace)
+ constructor(message: string) {
+ super(message)
this.name = 'NotFoundError'
}
}
@@ -74,8 +74,8 @@ export class NotFoundError extends SandboxError {
* Thrown when a file or directory is not found inside a sandbox.
*/
export class FileNotFoundError extends NotFoundError {
- constructor(message: string, stackTrace?: string) {
- super(message, stackTrace)
+ constructor(message: string) {
+ super(message)
this.name = 'FileNotFoundError'
}
}
@@ -84,8 +84,8 @@ export class FileNotFoundError extends NotFoundError {
* Thrown when a sandbox is not found (e.g. it doesn't exist or is no longer running).
*/
export class SandboxNotFoundError extends NotFoundError {
- constructor(message: string, stackTrace?: string) {
- super(message, stackTrace)
+ constructor(message: string) {
+ super(message)
this.name = 'SandboxNotFoundError'
}
}
@@ -114,8 +114,8 @@ export class GitAuthError extends AuthenticationError {
* Thrown when git upstream tracking is missing.
*/
export class GitUpstreamError extends SandboxError {
- constructor(message: string, stackTrace?: string) {
- super(message, stackTrace)
+ constructor(message: string) {
+ super(message)
this.name = 'GitUpstreamError'
}
}
@@ -125,8 +125,11 @@ export class GitUpstreamError extends SandboxError {
*/
export class TemplateError extends SandboxError {
constructor(message: string, stackTrace?: string) {
- super(message, stackTrace)
+ super(message)
this.name = 'TemplateError'
+ if (stackTrace) {
+ this.stack = stackTrace
+ }
}
}
@@ -178,9 +181,9 @@ export class VolumeError extends Error {
/**
* Thrown when a volume is not found.
*/
-export class VolumeNotFoundError extends NotFoundError {
- constructor(message: string, stackTrace?: string) {
- super(message, stackTrace)
+export class VolumeNotFoundError extends VolumeError {
+ constructor(message: string) {
+ super(message)
this.name = 'VolumeNotFoundError'
}
}
@@ -188,9 +191,9 @@ export class VolumeNotFoundError extends NotFoundError {
/**
* 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)
+export class VolumePathNotFoundError extends VolumeError {
+ constructor(message: string) {
+ super(message)
this.name = 'VolumePathNotFoundError'
}
}
diff --git a/packages/js-sdk/tests/volume/volume.test.ts b/packages/js-sdk/tests/volume/volume.test.ts
index d0b921a2c..b0f5bed88 100644
--- a/packages/js-sdk/tests/volume/volume.test.ts
+++ b/packages/js-sdk/tests/volume/volume.test.ts
@@ -5,7 +5,6 @@ import { randomUUID } from 'node:crypto'
import {
Volume,
- NotFoundError,
VolumeError,
VolumeNotFoundError,
VolumePathNotFoundError,
@@ -149,7 +148,7 @@ describe('Volume CRUD', () => {
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)
+ expect(err).toBeInstanceOf(VolumeError)
})
it('should throw VolumeError for a non-2xx response without content', async () => {
@@ -335,7 +334,7 @@ describe('Volume content readFile', () => {
const err = await vol.readFile('missing.txt').catch((err) => err)
expect(err).toBeInstanceOf(VolumePathNotFoundError)
- expect(err).toBeInstanceOf(NotFoundError)
+ expect(err).toBeInstanceOf(VolumeError)
})
it('should reject at call time for a missing file with stream format', async () => {