A domain refusal as a gRPC status carrying the contract's stable machine-readable ErrorInfo detail.
(code: ErrorCode, message: impl Into<String>)
| 387 | /// A domain refusal as a gRPC status carrying the contract's stable |
| 388 | /// machine-readable ErrorInfo detail. |
| 389 | pub fn domain_status(code: ErrorCode, message: impl Into<String>) -> Status { |
| 390 | let message: String = message.into(); |
| 391 | fn code_name(code: ErrorCode) -> &'static str { |
| 392 | match code { |
| 393 | ErrorCode::Unspecified => "ERROR_CODE_UNSPECIFIED", |
| 394 | ErrorCode::CapabilityUnavailable => "CAPABILITY_UNAVAILABLE", |
| 395 | ErrorCode::ProtocolVersionMismatch => "PROTOCOL_VERSION_MISMATCH", |
| 396 | ErrorCode::WorkspaceRequired => "WORKSPACE_REQUIRED", |
| 397 | ErrorCode::Unauthorized => "UNAUTHORIZED", |
| 398 | ErrorCode::Forbidden => "FORBIDDEN", |
| 399 | ErrorCode::SandboxToken => "SANDBOX_TOKEN", |
| 400 | ErrorCode::IdempotencyMismatch => "IDEMPOTENCY_MISMATCH", |
| 401 | ErrorCode::PreconditionFailed => "PRECONDITION_FAILED", |
| 402 | ErrorCode::GenerationConflict => "GENERATION_CONFLICT", |
| 403 | ErrorCode::InvalidArgument => "INVALID_ARGUMENT", |
| 404 | ErrorCode::NotFound => "NOT_FOUND", |
| 405 | ErrorCode::Repository => "REPOSITORY", |
| 406 | ErrorCode::RepositoryNotFound => "REPOSITORY_NOT_FOUND", |
| 407 | ErrorCode::ResourceExhausted => "RESOURCE_EXHAUSTED", |
| 408 | ErrorCode::RateLimited => "RATE_LIMITED", |
| 409 | ErrorCode::View => "VIEW", |
| 410 | ErrorCode::ViewStale => "VIEW_STALE", |
| 411 | ErrorCode::ChangeRejected => "CHANGE_REJECTED", |
| 412 | ErrorCode::ProvenanceStore => "PROVENANCE_STORE", |
| 413 | ErrorCode::ProvenanceCheckpoint => "PROVENANCE_CHECKPOINT", |
| 414 | ErrorCode::ProvenanceLifecycle => "PROVENANCE_LIFECYCLE", |
| 415 | ErrorCode::Provenance => "PROVENANCE", |
| 416 | ErrorCode::Changes => "CHANGES", |
| 417 | ErrorCode::FileStates => "FILE_STATES", |
| 418 | ErrorCode::Materialize => "MATERIALIZE", |
| 419 | ErrorCode::Remote => "REMOTE", |
| 420 | ErrorCode::Internal => "INTERNAL", |
| 421 | } |
| 422 | } |
| 423 | let info = ErrorInfo { |
| 424 | code: code as i32, |
| 425 | message: message.clone(), |
| 426 | context: HashMap::new(), |
| 427 | request_id: None, |
| 428 | }; |
| 429 | let mut payload = Vec::new(); |
| 430 | let _ = info.encode(&mut payload); |
| 431 | let _ = payload; |
| 432 | let grpc_code = match code { |
| 433 | ErrorCode::NotFound | ErrorCode::RepositoryNotFound => Code::NotFound, |
| 434 | ErrorCode::InvalidArgument => Code::InvalidArgument, |
| 435 | ErrorCode::PreconditionFailed |
| 436 | | ErrorCode::GenerationConflict |
| 437 | | ErrorCode::IdempotencyMismatch |
| 438 | | ErrorCode::ViewStale |
| 439 | | ErrorCode::ChangeRejected => Code::FailedPrecondition, |
| 440 | ErrorCode::ResourceExhausted | ErrorCode::RateLimited => Code::ResourceExhausted, |
| 441 | ErrorCode::Unauthorized => Code::Unauthenticated, |
| 442 | ErrorCode::Forbidden | ErrorCode::SandboxToken | ErrorCode::View => Code::PermissionDenied, |
| 443 | ErrorCode::ProtocolVersionMismatch => Code::Internal, |
| 444 | ErrorCode::Internal | ErrorCode::Repository => Code::Internal, |
| 445 | _ => Code::InvalidArgument, |
| 446 | }; |
no test coverage detected