Skip to content

Commit fdb256a

Browse files
committed
perf: sandbox error tip
1 parent a887673 commit fdb256a

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

packages/service/core/ai/sandbox/controller.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { getLogger, LogCategories } from '../../../common/logger';
1515
import { setCron } from '../../../common/system/cron';
1616
import { addMilliseconds } from 'date-fns';
1717
import { batchRun } from '@fastgpt/global/common/system/utils';
18+
import { getErrText } from '@fastgpt/global/common/error/utils';
1819
const logger = getLogger(LogCategories.MODULE.AI.SANDBOX);
1920

2021
type UnionIdType = {
@@ -97,17 +98,25 @@ export class SandboxClient {
9798
async exec(command: string, timeout?: number): Promise<ExecuteResult> {
9899
try {
99100
await this.ensureAvailable();
100-
} catch {
101+
} catch (err) {
101102
return {
102103
stdout: '',
103104
stderr: 'Sandbox service is not available, please try again later',
104105
exitCode: -1
105106
};
106107
}
107108

108-
return await this.provider.execute(command, {
109-
timeoutMs: timeout ? timeout * 1000 : undefined
110-
});
109+
return await this.provider
110+
.execute(command, {
111+
timeoutMs: timeout ? timeout * 1000 : undefined
112+
})
113+
.catch((err) => {
114+
return {
115+
stdout: '',
116+
stderr: getErrText(err),
117+
exitCode: -1
118+
};
119+
});
111120
}
112121

113122
async delete() {

test/cases/service/core/ai/sandbox/sandbox.integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ vi.mock('@fastgpt/service/env', () => ({
2323
AGENT_SANDBOX_SEALOS_TOKEN: process.env.AGENT_SANDBOX_SEALOS_TOKEN
2424
}
2525
}));
26-
console.log(hasSandboxEnv, 232323);
26+
2727
describe.skipIf(!hasSandboxEnv).sequential('Sandbox Integration', () => {
2828
const testDir = '/tmp/workspace';
2929
const testParams = {

0 commit comments

Comments
 (0)