Skip to content

Commit 4ffb211

Browse files
authored
Fix CLI compilation (#747)
Fix CLI compilation. Fixes nullable res.data & non-existent /teams endpoint in the OpenAPI generated client.
1 parent 1af267a commit 4ffb211

10 files changed

Lines changed: 67 additions & 49 deletions

File tree

packages/cli/src/commands/auth/configure.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ import * as e2b from 'e2b'
55
import * as path from 'path'
66

77
import { USER_CONFIG_PATH } from 'src/user'
8-
import {
9-
client,
10-
connectionConfig,
11-
ensureAccessToken,
12-
ensureUserConfig,
13-
} from 'src/api'
8+
import { client, connectionConfig, ensureAccessToken, ensureUserConfig } from 'src/api'
149
import { asBold, asFormattedTeam } from '../../utils/format'
1510
import { handleE2BRequestError } from '../../utils/errors'
1611

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

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

35-
handleE2BRequestError(res.error, 'Error getting teams')
30+
handleE2BRequestError(res, 'Error getting teams')
3631

3732
const team = (
3833
await inquirer.default.prompt([

packages/cli/src/commands/auth/login.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const loginCommand = new commander.Command('login')
5252
const client = new e2b.ApiClient(config)
5353
const res = await client.api.GET('/teams', { signal })
5454

55-
handleE2BRequestError(res.error, 'Error getting teams')
55+
handleE2BRequestError(res, 'Error getting teams')
5656

5757
const defaultTeam = res.data.find(
5858
(team: e2b.components['schemas']['Team']) => team.isDefault

packages/cli/src/commands/sandbox/list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as tablePrinter from 'console-table-printer'
22
import * as commander from 'commander'
33
import * as e2b from 'e2b'
44

5-
import { ensureAPIKey, client, connectionConfig } from 'src/api'
5+
import { client, connectionConfig, ensureAPIKey } from 'src/api'
66
import { handleE2BRequestError } from '../../utils/errors'
77

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

92-
handleE2BRequestError(res.error, 'Error getting running sandboxes')
92+
handleE2BRequestError(res, 'Error getting running sandboxes')
9393

9494
return res.data
9595
}

packages/cli/src/commands/sandbox/logs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ export async function listSandboxLogs({
311311
},
312312
})
313313

314-
handleE2BRequestError(res.error, 'Error while getting sandbox logs')
314+
handleE2BRequestError(res, 'Error while getting sandbox logs')
315315

316316
return res.data.logs
317317
}

packages/cli/src/commands/template/build.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as stripAnsi from 'strip-ansi'
66
import * as boxen from 'boxen'
77
import commandExists from 'command-exists'
88
import { wait } from 'src/utils/wait'
9-
import { connectionConfig, ensureAccessToken } from 'src/api'
9+
import { client, connectionConfig, ensureAccessToken } from 'src/api'
1010
import { getRoot } from 'src/utils/filesystem'
1111
import {
1212
asBold,
@@ -20,14 +20,9 @@ import {
2020
withDelimiter,
2121
} from 'src/utils/format'
2222
import { configOption, pathOption, teamOption } from 'src/options'
23-
import {
24-
defaultDockerfileName,
25-
fallbackDockerfileName,
26-
} from 'src/docker/constants'
23+
import { defaultDockerfileName, fallbackDockerfileName } from 'src/docker/constants'
2724
import { configName, getConfigPath, loadConfig, saveConfig } from 'src/config'
2825
import * as child_process from 'child_process'
29-
30-
import { client } from 'src/api'
3126
import { handleE2BRequestError } from '../../utils/errors'
3227
import { getUserConfig } from 'src/user'
3328
import { buildWithProxy } from './buildWithProxy'
@@ -60,12 +55,12 @@ async function getTemplateBuildLogs({
6055
}
6156
)
6257

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

6762
async function requestTemplateBuild(
68-
args?: e2b.paths['/templates']['post']['requestBody']['content']['application/json']
63+
args: e2b.paths['/templates']['post']['requestBody']['content']['application/json']
6964
) {
7065
return await client.api.POST('/templates', {
7166
body: args,
@@ -74,7 +69,7 @@ async function requestTemplateBuild(
7469

7570
async function requestTemplateRebuild(
7671
templateID: string,
77-
args?: e2b.paths['/templates/{templateID}']['post']['requestBody']['content']['application/json']
72+
args: e2b.paths['/templates/{templateID}']['post']['requestBody']['content']['application/json']
7873
) {
7974
return await client.api.POST('/templates/{templateID}', {
8075
body: args,
@@ -118,8 +113,8 @@ async function triggerTemplateBuild(templateID: string, buildID: string) {
118113
throw new Error('Error triggering template build')
119114
}
120115

121-
handleE2BRequestError(res?.error, 'Error triggering template build')
122-
return res?.data
116+
handleE2BRequestError(res, 'Error triggering template build')
117+
return res.data
123118
}
124119

125120
export const buildCommand = new commander.Command('build')
@@ -605,7 +600,7 @@ async function requestBuildTemplate(
605600
res = await requestTemplateBuild(args)
606601
}
607602

608-
handleE2BRequestError(res.error, 'Error requesting template build')
603+
handleE2BRequestError(res, 'Error requesting template build')
609604
return res.data
610605
}
611606

packages/cli/src/commands/template/delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function deleteTemplate(templateID: string) {
4040
},
4141
})
4242

43-
handleE2BRequestError(res.error, 'Error deleting sandbox template')
43+
handleE2BRequestError(res, 'Error deleting sandbox template')
4444
return
4545
}
4646

packages/cli/src/commands/template/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,6 @@ export async function listSandboxTemplates({
107107
},
108108
})
109109

110-
handleE2BRequestError(templates.error, 'Error getting templates')
110+
handleE2BRequestError(templates, 'Error getting templates')
111111
return templates.data
112112
}

packages/cli/src/commands/template/publish.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,9 @@ import * as commander from 'commander'
22
import * as chalk from 'chalk'
33
import * as fs from 'fs'
44

5-
import {
6-
asBold,
7-
asFormattedError,
8-
asFormattedSandboxTemplate,
9-
asLocal,
10-
asLocalRelative,
11-
} from 'src/utils/format'
12-
import {
13-
configOption,
14-
pathOption,
15-
selectMultipleOption,
16-
teamOption,
17-
} from 'src/options'
18-
import { E2BConfig, configName, getConfigPath, loadConfig } from 'src/config'
5+
import { asBold, asFormattedError, asFormattedSandboxTemplate, asLocal, asLocalRelative } from 'src/utils/format'
6+
import { configOption, pathOption, selectMultipleOption, teamOption } from 'src/options'
7+
import { configName, E2BConfig, getConfigPath, loadConfig } from 'src/config'
198
import { getRoot } from 'src/utils/filesystem'
209
import { listSandboxTemplates } from './list'
2110
import { getPromptTemplates } from 'src/utils/templatePrompt'
@@ -37,7 +26,7 @@ async function publishTemplate(templateID: string, publish: boolean) {
3726
})
3827

3928
handleE2BRequestError(
40-
res.error,
29+
res,
4130
`Error ${publish ? 'publishing' : 'unpublishing'} sandbox template`
4231
)
4332
return

packages/cli/src/utils/errors.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ export class E2BRequestError extends Error {
88
}
99
}
1010

11-
export function handleE2BRequestError(
12-
err?: { code: number; message: string },
11+
export function handleE2BRequestError<T>(
12+
res: { data?: T | null | undefined; error?: { code: number; message: string } },
1313
errMsg?: string,
14-
) {
15-
if (!err) {
14+
): asserts res is { data: T; error?: undefined } {
15+
if (!res.error && res.data != null) {
1616
return
1717
}
1818

19-
let message = ''
20-
switch (err.code) {
19+
let message = 'unknown error'
20+
const code = res.error?.code ?? 0
21+
switch (code) {
2122
case 400:
2223
message = 'bad request'
2324
break
@@ -36,8 +37,8 @@ export function handleE2BRequestError(
3637
}
3738

3839
throw new E2BRequestError(
39-
`${errMsg && `${errMsg}: `}[${err.code}] ${message && `${message}: `}${
40-
err.message ?? 'no message'
40+
`${errMsg && `${errMsg}: `}[${code}] ${message && `${message}: `}${
41+
res.error?.message ?? 'no message'
4142
}`,
4243
)
4344
}

packages/js-sdk/src/api/schema.gen.ts

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)