Skip to content

Commit

Permalink
Merge pull request #1558 from nightkr/bugfix/deserializeguard-error
Browse files Browse the repository at this point in the history
Implement Error for error_boundary::InvalidObject
  • Loading branch information
nightkr authored Aug 8, 2024
2 parents f0f47af + 2c1c79b commit e2ceea8
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions kube-core/src/error_boundary.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! Types for isolating deserialization failures. See [`DeserializeGuard`].

use std::{borrow::Cow, fmt::Display};
use std::borrow::Cow;

use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta;
use serde::Deserialize;
use serde_value::DeserializerError;
use thiserror::Error;

use crate::{PartialObjectMeta, Resource};

Expand All @@ -17,7 +18,8 @@ use crate::{PartialObjectMeta, Resource};
pub struct DeserializeGuard<K>(pub Result<K, InvalidObject>);

/// An object that failed to be deserialized by the [`DeserializeGuard`].
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Error)]
#[error("{error}")]
pub struct InvalidObject {
// Should ideally be D::Error, but we don't know what type it has outside of Deserialize::deserialize()
// It *could* be Box<std::error::Error>, but we don't know that it is Send+Sync
Expand All @@ -27,12 +29,6 @@ pub struct InvalidObject {
pub metadata: ObjectMeta,
}

impl Display for InvalidObject {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.error.fmt(f)
}
}

impl<'de, K> Deserialize<'de> for DeserializeGuard<K>
where
K: Deserialize<'de>,
Expand Down

0 comments on commit e2ceea8

Please sign in to comment.