Skip to content

Commit add40bc

Browse files
Marlon Costayhmo
authored andcommitted
fix(error): use status.code instead of error_code for Milvus > 2.3 compatibility
1 parent 5a4a3aa commit add40bc

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/error.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// For custom error handling
1717
// TODO
1818

19+
use std::convert::TryFrom;
20+
1921
use crate::collection::Error as CollectionError;
2022
use crate::proto::common::{ErrorCode, Status};
2123
use crate::schema::Error as SchemaError;
@@ -73,7 +75,13 @@ pub enum Error {
7375

7476
impl From<Status> for Error {
7577
fn from(s: Status) -> Self {
76-
Error::Server(ErrorCode::from_i32(s.error_code).unwrap(), s.reason)
78+
let code = ErrorCode::try_from(s.code).unwrap_or(ErrorCode::UnexpectedError);
79+
let reason = if code == ErrorCode::UnexpectedError && s.code != code as i32 {
80+
format!("{} (code {})", s.reason, s.code)
81+
} else {
82+
s.reason
83+
};
84+
Error::Server(code, reason)
7785
}
7886
}
7987

src/utils.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17+
use std::convert::TryFrom;
18+
1719
use crate::{
1820
error::Error,
1921
proto::common::{ErrorCode, Status},
@@ -24,14 +26,12 @@ pub fn status_to_result(status: &Option<Status>) -> Result<(), Error> {
2426
.clone()
2527
.ok_or(Error::Unexpected("no status".to_owned()))?;
2628

27-
match ErrorCode::from_i32(status.error_code) {
28-
Some(i) => match i {
29-
ErrorCode::Success => Ok(()),
30-
_ => Err(Error::from(status)),
31-
},
32-
None => Err(Error::Unexpected(format!(
33-
"unknown error code {}",
34-
status.error_code
35-
))),
29+
match ErrorCode::try_from(status.code) {
30+
Ok(ErrorCode::Success) => Ok(()),
31+
Ok(_) => Err(Error::from(status)),
32+
Err(_) => Err(Error::Server(
33+
ErrorCode::UnexpectedError,
34+
format!("{} (code {})", status.reason, status.code),
35+
)),
3636
}
3737
}

0 commit comments

Comments
 (0)