cubeapi: map missing sandbox template to bad request on create#70
Conversation
|
The failed GitHub Action appears to come from the repository’s automated Claude review workflow permission check for external contributors. The log shows my actor permission is |
| Self::Api { ret_code, ret_msg } => { | ||
| *ret_code == 130400 && ret_msg.to_lowercase().contains("template not found") | ||
| } |
There was a problem hiding this comment.
This is poorly written. The corresponding error codes should be returned in Cubemaster, rather than using string matching to determine them.
| if e.is_template_not_found() { | ||
| AppError::NotFound(format!("template {} not found", body.template_id)) | ||
| } else { | ||
| AppError::Internal(anyhow::anyhow!(e.to_string())) | ||
| } | ||
| })?; | ||
| resp.ret | ||
| .into_result() | ||
| .map_err(|e| AppError::Internal(anyhow::anyhow!(e.to_string())))?; | ||
| .map_err(|e| { | ||
| if e.is_template_not_found() { | ||
| AppError::NotFound(format!("template {} not found", body.template_id)) | ||
| } else { | ||
| AppError::Internal(anyhow::anyhow!(e.to_string())) | ||
| } | ||
| })?; |
There was a problem hiding this comment.
Perhaps the return value should adhere to the conventions specified in https://github.com/e2b-dev/E2B/blob/main/spec/openapi.yml#L1949 ?
|
Addressed the requested changes in the latest update:
Validation run locally:
Please take another look when convenient. Thanks! |
chenhengqi
left a comment
There was a problem hiding this comment.
- Please organize you commits logically, one commit per component.
- Please follow our AI-Generated Code Policy in contributing guide.
35326bd to
68c6995
Compare
|
I reorganized the PR into two logical commits, one for CubeMaster and one for CubeAPI. I reviewed the AI-assisted changes myself and added my own Signed-off-by trailers according to the project’s AI-Generated Code Policy and DCO requirements. |
| "github.com/tencentcloud/CubeSandbox/CubeMaster/pkg/base/constants" | ||
| "github.com/tencentcloud/CubeSandbox/CubeMaster/pkg/errorcode" | ||
| "github.com/tencentcloud/CubeSandbox/CubeMaster/pkg/service/sandbox/types" | ||
| CubeLog "github.com/tencentcloud/CubeSandbox/cubelog" |
There was a problem hiding this comment.
Why do we need this change?
There was a problem hiding this comment.
This import is needed because sandbox_preview_test.go already uses CubeLog.RequestTrace{} in existing tests. Without it, the cube package tests fail to compile before reaching the new sandbox creation tests. I kept the change minimal to only add the missing import.
| "github.com/tencentcloud/CubeSandbox/cubelog" | ||
| ) | ||
|
|
||
| var createSandboxDealCubeboxCreateReqWithTemplateFn = dealCubeboxCreateReqWithTemplate |
There was a problem hiding this comment.
Please group variables:
var (
...
)
There was a problem hiding this comment.
Updated. I grouped the test hook variables into a single var (...) block.
Signed-off-by: YangYuS8 <YangYuS8@163.com>
Signed-off-by: YangYuS8 <YangYuS8@163.com>
68c6995 to
0f4fc1a
Compare
|
Hi @chenhengqi, gentle ping on this PR. I’ve addressed the latest review comments and kept the PR organized as two signed-off commits, one for CubeMaster and one for CubeAPI. Please let me know if there is anything else I should adjust. Thanks! |
|
/cubebot review this pr |
|
Claude finished @chenhengqi's task in 2m 38s —— View job PR ReviewReviewed the two commits on CubeMaster (
|
Summary
POST /sandboxesProblem
When creating a sandbox with a non-existent template, CubeMaster previously returned a params error and CubeAPI ended up returning an incorrect HTTP response.
Fix
create_sandboxto rely on CubeMaster error codes instead of string matchingPOST /sandboxesmissing-template case according to the E2B spec for this endpointCloses [Bug Report] CubeAPI returns HTTP 500 instead of 400/404 when creating sandbox with non-existent template #10
Validation
cd CubeAPI && cargo +1.88.0 testcd CubeAPI && cargo +1.88.0 checkcd CubeMaster && go test ./pkg/templatecenter -run TestGetTemplateRequestAssignsRuntimeRequestIDNotes
CubeMaster/pkg/service/httpservice/cubewere not expanded beyond the minimum necessary scope.