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>,
)
| 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. |
| 1125 | fn 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 | |
| 1151 | impl super::WorkspaceServices { |
| 1152 | /// Build a workspace whose files live in an S3-compatible bucket. |
no test coverage detected