Skip to content

Commit 5595b61

Browse files
fix: Add back DecodeError::new (#1382)
* fix: Add back `DecodeError::new` This function was meant for internal use only. Because of `doc(hidden)` it was publicly available and it is actually used by users. The prost 0.14.2 release broken some of the crate ecosystem. That release was yanked. To prevent more breakage, this PR adds the function back. This time as a public function that is documented to not be used. The prost project intents to remove this function in the next breaking release. * Apply suggestion from @LucioFranco --------- Co-authored-by: Lucio Franco <luciofranco14@gmail.com>
1 parent e42dcad commit 5595b61

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

prost/src/error.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Protobuf encoding and decoding errors.
22
33
use crate::encoding::WireType;
4+
use alloc::borrow::Cow;
45
#[cfg(not(feature = "std"))]
56
use alloc::boxed::Box;
67
#[cfg(not(feature = "std"))]
@@ -30,9 +31,25 @@ struct Inner {
3031
}
3132

3233
impl DecodeError {
34+
/// Creates a new `DecodeError` with a 'best effort' root cause description.
35+
///
36+
/// Meant to be used only by `Message` implementations.
37+
#[deprecated(
38+
since = "0.14.2",
39+
note = "This function was meant for internal use only. Because of `doc(hidden)` it was publicly available and it is actually used by users. The prost project intents to remove this function in the next breaking release."
40+
)]
41+
#[cold]
42+
#[doc(hidden)]
43+
pub fn new(description: impl Into<Cow<'static, str>>) -> DecodeError {
44+
DecodeErrorKind::Other {
45+
description: description.into(),
46+
}
47+
.into()
48+
}
49+
3350
/// Creates a new `DecodeError` with a DecodeErrorKind::UnexpectedTypeUrl.
3451
///
35-
/// Meant to be used only by `prost_types::Any` implementation.
52+
/// Must only be used by `prost_types::Any` implementation.
3653
#[doc(hidden)]
3754
#[cold]
3855
pub fn new_unexpected_type_url(
@@ -115,6 +132,8 @@ pub(crate) enum DecodeErrorKind {
115132
InvalidString,
116133
/// Unexpected type URL
117134
UnexpectedTypeUrl { actual: String, expected: String },
135+
/// A textual description of a problem
136+
Other { description: Cow<'static, str> },
118137
}
119138

120139
impl fmt::Display for DecodeErrorKind {
@@ -141,6 +160,9 @@ impl fmt::Display for DecodeErrorKind {
141160
Self::UnexpectedTypeUrl { actual, expected } => {
142161
write!(f, "unexpected type URL.type_url: expected type URL: \"{expected}\" (got: \"{actual}\")")
143162
}
163+
Self::Other { description } => {
164+
write!(f, "{description}")
165+
}
144166
}
145167
}
146168
}

0 commit comments

Comments
 (0)