Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Error for error_boundary::InvalidObject #1558

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading