Skip to content

Commit f2009aa

Browse files
committed
Drop description and fallback logic that is no longer used by cargo_err
1 parent c84368a commit f2009aa

File tree

2 files changed

+4
-81
lines changed

2 files changed

+4
-81
lines changed

src/util/errors.rs

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ struct Bad {
4242
// AppError trait
4343

4444
pub trait AppError: Send + fmt::Display + fmt::Debug + 'static {
45-
fn description(&self) -> &str;
4645
fn cause(&self) -> Option<&(dyn AppError)> {
4746
None
4847
}
@@ -53,30 +52,6 @@ pub trait AppError: Send + fmt::Display + fmt::Debug + 'static {
5352
/// where it is eventually logged and turned into a status 500 response.
5453
fn response(&self) -> Option<Response>;
5554

56-
/// Fallback logic for generating a cargo friendly response
57-
///
58-
/// This behavior is deprecated and no new calls or impls should be added.
59-
fn fallback_response(&self) -> Option<Response> {
60-
if self.fallback_with_description_as_bad_200() {
61-
Some(json_response(&Bad {
62-
errors: vec![StringError {
63-
detail: self.description().to_string(),
64-
}],
65-
}))
66-
} else {
67-
self.cause().and_then(AppError::response)
68-
}
69-
}
70-
71-
/// Determines if the `fallback_response` method should send the description as a status 200
72-
/// error to cargo, or send the cause response (if applicable).
73-
///
74-
/// This is only to be used by the `fallback_response` method. If your error type impls
75-
/// `response`, then there is no need to impl this method.
76-
fn fallback_with_description_as_bad_200(&self) -> bool {
77-
false
78-
}
79-
8055
fn get_type_id(&self) -> TypeId {
8156
TypeId::of::<Self>()
8257
}
@@ -105,15 +80,9 @@ impl dyn AppError {
10580
}
10681

10782
impl AppError for Box<dyn AppError> {
108-
fn description(&self) -> &str {
109-
(**self).description()
110-
}
11183
fn cause(&self) -> Option<&dyn AppError> {
11284
(**self).cause()
11385
}
114-
fn fallback_with_description_as_bad_200(&self) -> bool {
115-
(**self).fallback_with_description_as_bad_200()
116-
}
11786
fn response(&self) -> Option<Response> {
11887
(**self).response()
11988
}
@@ -179,18 +148,12 @@ impl<T> ChainError<T> for Option<T> {
179148
}
180149

181150
impl<E: AppError> AppError for ChainedError<E> {
182-
fn description(&self) -> &str {
183-
self.error.description()
184-
}
185151
fn cause(&self) -> Option<&dyn AppError> {
186152
Some(&*self.cause)
187153
}
188154
fn response(&self) -> Option<Response> {
189155
self.error.response()
190156
}
191-
fn fallback_with_description_as_bad_200(&self) -> bool {
192-
self.error.fallback_with_description_as_bad_200()
193-
}
194157
}
195158

196159
impl<E: AppError> fmt::Display for ChainedError<E> {
@@ -203,11 +166,8 @@ impl<E: AppError> fmt::Display for ChainedError<E> {
203166
// Error impls
204167

205168
impl<E: Error + Send + 'static> AppError for E {
206-
fn description(&self) -> &str {
207-
Error::description(self)
208-
}
209169
fn response(&self) -> Option<Response> {
210-
self.fallback_response()
170+
None
211171
}
212172
}
213173

@@ -219,6 +179,7 @@ impl<E: Error + Send + 'static> From<E> for Box<dyn AppError> {
219179
// =============================================================================
220180
// Concrete errors
221181

182+
// TODO: Rename to InternalAppError
222183
#[derive(Debug)]
223184
struct ConcreteAppError {
224185
description: String,
@@ -232,25 +193,15 @@ impl fmt::Display for ConcreteAppError {
232193
}
233194

234195
impl AppError for ConcreteAppError {
235-
fn description(&self) -> &str {
236-
&self.description
237-
}
238-
fn cause(&self) -> Option<&dyn AppError> {
239-
None
240-
}
241196
fn response(&self) -> Option<Response> {
242-
self.fallback_response()
197+
None
243198
}
244199
}
245200

246201
#[derive(Debug, Clone, Copy)]
247202
pub struct NotFound;
248203

249204
impl AppError for NotFound {
250-
fn description(&self) -> &str {
251-
"not found"
252-
}
253-
254205
fn response(&self) -> Option<Response> {
255206
let mut response = json_response(&Bad {
256207
errors: vec![StringError {
@@ -272,10 +223,6 @@ impl fmt::Display for NotFound {
272223
pub struct Unauthorized;
273224

274225
impl AppError for Unauthorized {
275-
fn description(&self) -> &str {
276-
"unauthorized"
277-
}
278-
279226
fn response(&self) -> Option<Response> {
280227
let mut response = json_response(&Bad {
281228
errors: vec![StringError {
@@ -297,10 +244,6 @@ impl fmt::Display for Unauthorized {
297244
struct BadRequest(String);
298245

299246
impl AppError for BadRequest {
300-
fn description(&self) -> &str {
301-
self.0.as_ref()
302-
}
303-
304247
fn response(&self) -> Option<Response> {
305248
let mut response = json_response(&Bad {
306249
errors: vec![StringError {
@@ -338,11 +281,7 @@ pub fn bad_request<S: ToString + ?Sized>(error: &S) -> Box<dyn AppError> {
338281
#[derive(Debug)]
339282
pub struct AppErrToStdErr(pub Box<dyn AppError>);
340283

341-
impl Error for AppErrToStdErr {
342-
fn description(&self) -> &str {
343-
self.0.description()
344-
}
345-
}
284+
impl Error for AppErrToStdErr {}
346285

347286
impl fmt::Display for AppErrToStdErr {
348287
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -370,10 +309,6 @@ pub(crate) fn std_error_no_send(e: Box<dyn AppError>) -> Box<dyn Error> {
370309
pub struct ReadOnlyMode;
371310

372311
impl AppError for ReadOnlyMode {
373-
fn description(&self) -> &str {
374-
"tried to write in read only mode"
375-
}
376-
377312
fn response(&self) -> Option<Response> {
378313
let mut response = json_response(&Bad {
379314
errors: vec![StringError {
@@ -399,10 +334,6 @@ pub struct TooManyRequests {
399334
}
400335

401336
impl AppError for TooManyRequests {
402-
fn description(&self) -> &str {
403-
"too many requests"
404-
}
405-
406337
fn response(&self) -> Option<Response> {
407338
const HTTP_DATE_FORMAT: &str = "%a, %d %b %Y %H:%M:%S GMT";
408339
let retry_after = self.retry_after.format(HTTP_DATE_FORMAT);

src/util/errors/http.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ pub(super) struct Ok(pub(super) String);
1111
pub(super) struct ServerError(pub(super) String);
1212

1313
impl AppError for Ok {
14-
fn description(&self) -> &str {
15-
self.0.as_ref()
16-
}
17-
1814
fn response(&self) -> Option<Response> {
1915
Some(json_response(&Bad {
2016
errors: vec![StringError {
@@ -31,10 +27,6 @@ impl fmt::Display for Ok {
3127
}
3228

3329
impl AppError for ServerError {
34-
fn description(&self) -> &str {
35-
self.0.as_ref()
36-
}
37-
3830
fn response(&self) -> Option<Response> {
3931
let mut response = json_response(&Bad {
4032
errors: vec![StringError {

0 commit comments

Comments
 (0)