MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / status_message

Function status_message

atomic-cli/src/service/mod.rs:258–307  ·  view source on GitHub ↗

A transport/domain refusal surfaced with its contract vocabulary. The handler already encodes the stable error code and the human message (`atomic:VIEW: ...`); the gRPC plumbing around it is transport noise. User-fixable refusals (preconditions, bad arguments, not-found, permission) exit as user errors — only genuine internal failures are bugs.

(error: tonic::Status)

Source from the content-addressed store, hash-verified

256/// permission) exit as user errors — only genuine internal failures are
257/// bugs.
258pub fn status_message(error: tonic::Status) -> CliError {
259 use tonic::Code;
260 if error.code() == Code::FailedPrecondition
261 && error
262 .metadata()
263 .get("atomic-record-error")
264 .and_then(|value| value.to_str().ok())
265 == Some("file-too-large")
266 {
267 let parsed = (|| {
268 let path = error
269 .metadata()
270 .get_bin("atomic-file-path-bin")?
271 .to_bytes()
272 .ok()?;
273 let path = String::from_utf8(path.to_vec()).ok()?;
274 let size = error
275 .metadata()
276 .get("atomic-file-size")?
277 .to_str()
278 .ok()?
279 .parse()
280 .ok()?;
281 let limit = error
282 .metadata()
283 .get("atomic-file-limit")?
284 .to_str()
285 .ok()?
286 .parse()
287 .ok()?;
288 Some(CliError::FileTooLarge { path, size, limit })
289 })();
290 if let Some(error) = parsed {
291 return error;
292 }
293 }
294 let message = error.message().to_string();
295 match error.code() {
296 Code::FailedPrecondition
297 | Code::InvalidArgument
298 | Code::NotFound
299 | Code::AlreadyExists
300 | Code::PermissionDenied
301 | Code::Unauthenticated
302 | Code::ResourceExhausted
303 | Code::Cancelled
304 | Code::Unavailable => CliError::ServiceRefusal { message },
305 _ => CliError::Internal(anyhow::anyhow!("{message}")),
306 }
307}
308
309// ---------------------------------------------------------------------------
310// DaemonService (session keep-alive)

Callers

nothing calls this directly

Calls 7

getMethod · 0.65
codeMethod · 0.45
metadataMethod · 0.45
okMethod · 0.45
to_bytesMethod · 0.45
parseMethod · 0.45
messageMethod · 0.45

Tested by

no test coverage detected