MCPcopy Create free account
hub / github.com/AI45Lab/Code / map_put_error

Function map_put_error

core/src/workspace/s3.rs:1125–1149  ·  view source on GitHub ↗

Map a `PutObject` failure to either a [`WorkspaceVersionConflict`] (HTTP 412 Precondition Failed from `If-Match`) or a generic write error. AWS S3 does not return the current ETag on 412 so [`WorkspaceVersionConflict::actual`] is left `None`; callers that need the current version must re-read.

(
    bucket: &str,
    key: &str,
    expected_version: &str,
    error: SdkError<PutObjectError>,
)

Source from the content-addressed store, hash-verified

1123/// AWS S3 does not return the current ETag on 412 so [`WorkspaceVersionConflict::actual`]
1124/// is left `None`; callers that need the current version must re-read.
1125fn map_put_error(
1126 bucket: &str,
1127 key: &str,
1128 expected_version: &str,
1129 error: SdkError<PutObjectError>,
1130) -> WorkspaceError {
1131 let status = error
1132 .raw_response()
1133 .map(|r| r.status().as_u16())
1134 .unwrap_or_default();
1135 if status == 412 {
1136 WorkspaceError::VersionConflict(WorkspaceVersionConflict {
1137 path: format!("s3://{}/{}", bucket, key),
1138 expected: expected_version.to_string(),
1139 actual: None,
1140 })
1141 } else {
1142 WorkspaceError::Backend(anyhow!(
1143 "Failed to write S3 object s3://{}/{}: {}",
1144 bucket,
1145 key,
1146 error
1147 ))
1148 }
1149}
1150
1151impl super::WorkspaceServices {
1152 /// Build a workspace whose files live in an S3-compatible bucket.

Callers 1

write_text_if_versionMethod · 0.85

Calls 1

statusMethod · 0.45

Tested by

no test coverage detected