Skip to content

Fix CLI compilation #747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions packages/cli/src/commands/auth/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import * as e2b from 'e2b'
import * as path from 'path'

import { USER_CONFIG_PATH } from 'src/user'
import {
client,
connectionConfig,
ensureAccessToken,
ensureUserConfig,
} from 'src/api'
import { client, connectionConfig, ensureAccessToken, ensureUserConfig } from 'src/api'
import { asBold, asFormattedTeam } from '../../utils/format'
import { handleE2BRequestError } from '../../utils/errors'

Expand All @@ -32,7 +27,7 @@ export const configureCommand = new commander.Command('configure')

const res = await client.api.GET('/teams', { signal })

handleE2BRequestError(res.error, 'Error getting teams')
handleE2BRequestError(res, 'Error getting teams')

const team = (
await inquirer.default.prompt([
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const loginCommand = new commander.Command('login')
const client = new e2b.ApiClient(config)
const res = await client.api.GET('/teams', { signal })

handleE2BRequestError(res.error, 'Error getting teams')
handleE2BRequestError(res, 'Error getting teams')

const defaultTeam = res.data.find(
(team: e2b.components['schemas']['Team']) => team.isDefault
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/sandbox/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as tablePrinter from 'console-table-printer'
import * as commander from 'commander'
import * as e2b from 'e2b'

import { ensureAPIKey, client, connectionConfig } from 'src/api'
import { client, connectionConfig, ensureAPIKey } from 'src/api'
import { handleE2BRequestError } from '../../utils/errors'

export const listCommand = new commander.Command('list')
Expand Down Expand Up @@ -89,7 +89,7 @@ export async function listSandboxes(): Promise<
const signal = connectionConfig.getSignal()
const res = await client.api.GET('/sandboxes', { signal })

handleE2BRequestError(res.error, 'Error getting running sandboxes')
handleE2BRequestError(res, 'Error getting running sandboxes')

return res.data
}
2 changes: 1 addition & 1 deletion packages/cli/src/commands/sandbox/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export async function listSandboxLogs({
},
})

handleE2BRequestError(res.error, 'Error while getting sandbox logs')
handleE2BRequestError(res, 'Error while getting sandbox logs')

return res.data.logs
}
21 changes: 8 additions & 13 deletions packages/cli/src/commands/template/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as stripAnsi from 'strip-ansi'
import * as boxen from 'boxen'
import commandExists from 'command-exists'
import { wait } from 'src/utils/wait'
import { connectionConfig, ensureAccessToken } from 'src/api'
import { client, connectionConfig, ensureAccessToken } from 'src/api'
import { getRoot } from 'src/utils/filesystem'
import {
asBold,
Expand All @@ -20,14 +20,9 @@ import {
withDelimiter,
} from 'src/utils/format'
import { configOption, pathOption, teamOption } from 'src/options'
import {
defaultDockerfileName,
fallbackDockerfileName,
} from 'src/docker/constants'
import { defaultDockerfileName, fallbackDockerfileName } from 'src/docker/constants'
import { configName, getConfigPath, loadConfig, saveConfig } from 'src/config'
import * as child_process from 'child_process'

import { client } from 'src/api'
import { handleE2BRequestError } from '../../utils/errors'
import { getUserConfig } from 'src/user'
import { buildWithProxy } from './buildWithProxy'
Expand Down Expand Up @@ -60,12 +55,12 @@ async function getTemplateBuildLogs({
}
)

handleE2BRequestError(res.error, 'Error getting template build status')
handleE2BRequestError(res, 'Error getting template build status')
return res.data as e2b.paths['/templates/{templateID}/builds/{buildID}/status']['get']['responses']['200']['content']['application/json']
}

async function requestTemplateBuild(
args?: e2b.paths['/templates']['post']['requestBody']['content']['application/json']
args: e2b.paths['/templates']['post']['requestBody']['content']['application/json']
) {
return await client.api.POST('/templates', {
body: args,
Expand All @@ -74,7 +69,7 @@ async function requestTemplateBuild(

async function requestTemplateRebuild(
templateID: string,
args?: e2b.paths['/templates/{templateID}']['post']['requestBody']['content']['application/json']
args: e2b.paths['/templates/{templateID}']['post']['requestBody']['content']['application/json']
) {
return await client.api.POST('/templates/{templateID}', {
body: args,
Expand Down Expand Up @@ -118,8 +113,8 @@ async function triggerTemplateBuild(templateID: string, buildID: string) {
throw new Error('Error triggering template build')
}

handleE2BRequestError(res?.error, 'Error triggering template build')
return res?.data
handleE2BRequestError(res, 'Error triggering template build')
return res.data
}

export const buildCommand = new commander.Command('build')
Expand Down Expand Up @@ -605,7 +600,7 @@ async function requestBuildTemplate(
res = await requestTemplateBuild(args)
}

handleE2BRequestError(res.error, 'Error requesting template build')
handleE2BRequestError(res, 'Error requesting template build')
return res.data
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/template/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function deleteTemplate(templateID: string) {
},
})

handleE2BRequestError(res.error, 'Error deleting sandbox template')
handleE2BRequestError(res, 'Error deleting sandbox template')
return
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/template/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ export async function listSandboxTemplates({
},
})

handleE2BRequestError(templates.error, 'Error getting templates')
handleE2BRequestError(templates, 'Error getting templates')
return templates.data
}
19 changes: 4 additions & 15 deletions packages/cli/src/commands/template/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,9 @@ import * as commander from 'commander'
import * as chalk from 'chalk'
import * as fs from 'fs'

import {
asBold,
asFormattedError,
asFormattedSandboxTemplate,
asLocal,
asLocalRelative,
} from 'src/utils/format'
import {
configOption,
pathOption,
selectMultipleOption,
teamOption,
} from 'src/options'
import { E2BConfig, configName, getConfigPath, loadConfig } from 'src/config'
import { asBold, asFormattedError, asFormattedSandboxTemplate, asLocal, asLocalRelative } from 'src/utils/format'
import { configOption, pathOption, selectMultipleOption, teamOption } from 'src/options'
import { configName, E2BConfig, getConfigPath, loadConfig } from 'src/config'
import { getRoot } from 'src/utils/filesystem'
import { listSandboxTemplates } from './list'
import { getPromptTemplates } from 'src/utils/templatePrompt'
Expand All @@ -37,7 +26,7 @@ async function publishTemplate(templateID: string, publish: boolean) {
})

handleE2BRequestError(
res.error,
res,
`Error ${publish ? 'publishing' : 'unpublishing'} sandbox template`
)
return
Expand Down
17 changes: 9 additions & 8 deletions packages/cli/src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ export class E2BRequestError extends Error {
}
}

export function handleE2BRequestError(
err?: { code: number; message: string },
export function handleE2BRequestError<T>(
res: { data?: T | null | undefined; error?: { code: number; message: string } },
errMsg?: string,
) {
if (!err) {
): asserts res is { data: T; error?: undefined } {
if (!res.error && res.data != null) {
return
}

let message = ''
switch (err.code) {
let message = 'unknown error'
const code = res.error?.code ?? 0
switch (code) {
case 400:
message = 'bad request'
break
Expand All @@ -36,8 +37,8 @@ export function handleE2BRequestError(
}

throw new E2BRequestError(
`${errMsg && `${errMsg}: `}[${err.code}] ${message && `${message}: `}${
err.message ?? 'no message'
`${errMsg && `${errMsg}: `}[${code}] ${message && `${message}: `}${
res.error?.message ?? 'no message'
}`,
)
}
38 changes: 38 additions & 0 deletions packages/js-sdk/src/api/schema.gen.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.