Skip to content

Commit

Permalink
fix(services/dropbox): fix dropbox batch test panic in ci (#4329)
Browse files Browse the repository at this point in the history
* add error deserialization structure for batch

* ignore path_lookup not_found error

* improve comment
  • Loading branch information
zjregee authored Mar 7, 2024
1 parent e6c7cfb commit 53aa0b1
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions core/src/services/dropbox/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

use std::collections::HashMap;
use std::default::Default;
use std::fmt::Debug;
use std::fmt::Formatter;
Expand All @@ -37,7 +38,6 @@ use serde::Serialize;
use tokio::sync::Mutex;

use super::error::parse_error;
use super::error::DropboxErrorResponse;
use crate::raw::*;
use crate::*;

Expand Down Expand Up @@ -337,12 +337,22 @@ impl DropboxCore {
(path, Ok(RpDelete::default().into()))
}
"failure" => {
let error = entry.error.expect("error should be present");
let err = Error::new(
ErrorKind::Unexpected,
&format!("delete failed with error {}", error.error_summary),
);
("".to_string(), Err(err))
let error = entry.failure.expect("error should be present");
let error_cause = &error
.failure_cause_map
.get(&error.tag)
.expect("error should be present")
.tag;
// Ignore errors about path lookup not found and report others.
if error.tag == "path_lookup" && error_cause == "not_found" {
("".to_string(), Ok(RpDelete::default().into()))
} else {
let err = Error::new(
ErrorKind::Unexpected,
&format!("delete failed with error {} {}", error.tag, error_cause),
);
("".to_string(), Err(err))
}
}
_ => (
"".to_string(),
Expand Down Expand Up @@ -515,5 +525,26 @@ pub struct DropboxDeleteBatchResponseEntry {
#[serde(rename(deserialize = ".tag"))]
pub tag: String,
pub metadata: Option<DropboxMetadataResponse>,
pub error: Option<DropboxErrorResponse>,
pub failure: Option<DropboxDeleteBatchFailureResponse>,
}

#[derive(Default, Debug, Deserialize)]
#[serde(default)]
pub struct DropboxDeleteBatchFailureResponse {
#[serde(rename(deserialize = ".tag"))]
pub tag: String,
// During the batch deletion process, Dropbox returns
// part of the error information in the form of a JSON key.
// Since it is impossible to determine the JSON key in advance,
// the error information is parsed into a HashMap here.
// The key of the HashMap is equal to the value of the tag above.
#[serde(flatten)]
pub failure_cause_map: HashMap<String, DropboxDeleteBatchFailureResponseCause>,
}

#[derive(Default, Debug, Deserialize)]
#[serde(default)]
pub struct DropboxDeleteBatchFailureResponseCause {
#[serde(rename(deserialize = ".tag"))]
pub tag: String,
}

0 comments on commit 53aa0b1

Please sign in to comment.