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

Function status_message

atomic-cli/src/service/mod.rs:260–309  ·  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

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