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

Function rejection_error_info

libatomic/src/daemon/sandbox_wire.rs:247–290  ·  view source on GitHub ↗

A refusal as the contract's [`pb::ErrorInfo`]: `VIEW_STALE` for a stale view, `CHANGE_REJECTED` otherwise, with the variant in [`REJECTION_REASON`] and its fields beside it so the other side can rebuild it ([`rejection_from_error_info`]).

(rejection: &SubmitRejection)

Source from the content-addressed store, hash-verified

245/// [`REJECTION_REASON`] and its fields beside it so the other side can
246/// rebuild it ([`rejection_from_error_info`]).
247pub fn rejection_error_info(rejection: &SubmitRejection) -> pb::ErrorInfo {
248 let mut context = HashMap::new();
249 let mut put = |k: &str, v: &str| {
250 context.insert(k.to_string(), v.to_string());
251 };
252 let (code, reason) = match rejection {
253 SubmitRejection::HashMismatch { claimed, computed } => {
254 put("claimed", claimed);
255 put("computed", computed);
256 (ErrorCode::ChangeRejected, "hash_mismatch")
257 }
258 SubmitRejection::Malformed(why) => {
259 put("detail", why);
260 (ErrorCode::ChangeRejected, "malformed")
261 }
262 SubmitRejection::StaleView { current } => {
263 put("current", current);
264 (ErrorCode::ViewStale, "stale_view")
265 }
266 SubmitRejection::ForeignChange(change) => {
267 put("change", change);
268 (ErrorCode::ChangeRejected, "foreign_change")
269 }
270 SubmitRejection::ForeignNode(node) => {
271 put("node", &node.to_string());
272 (ErrorCode::ChangeRejected, "foreign_node")
273 }
274 SubmitRejection::ForbiddenPath(path) => {
275 put("path", path);
276 (ErrorCode::ChangeRejected, "forbidden_path")
277 }
278 SubmitRejection::AlreadyPresent(change) => {
279 put("change", change);
280 (ErrorCode::ChangeRejected, "already_present")
281 }
282 };
283 put(REJECTION_REASON, reason);
284 pb::ErrorInfo {
285 code: code as i32,
286 message: rejection.to_string(),
287 context,
288 request_id: None,
289 }
290}
291
292/// The [`SubmitRejection`] an [`pb::ErrorInfo`] from
293/// [`rejection_error_info`] describes, if it is one.

Callers 5

get_changesMethod · 0.85
publish_provenanceMethod · 0.85
submit_changeMethod · 0.85
submit_attestationMethod · 0.85

Calls 2

putFunction · 0.50
insertMethod · 0.45

Tested by 1