@@ -14,10 +14,6 @@ extern crate alloc;
1414use alloc:: string:: FromUtf8Error ;
1515use core:: array:: TryFromSliceError ;
1616
17- use crate :: kvs_value:: KvsValue ;
18- use std:: collections:: HashMap ;
19- use std:: sync:: { MutexGuard , PoisonError } ;
20-
2117/// Runtime Error Codes
2218#[ derive( Debug , PartialEq ) ]
2319pub enum ErrorCode {
@@ -75,11 +71,17 @@ pub enum ErrorCode {
7571 /// Invalid snapshot ID
7672 InvalidSnapshotId ,
7773
74+ /// Invalid instance ID
75+ InvalidInstanceId ,
76+
7877 /// Conversion failed
7978 ConversionFailed ,
8079
8180 /// Mutex failed
8281 MutexLockFailed ,
82+
83+ /// Instance parameters mismatch
84+ InstanceParametersMismatch ,
8385}
8486
8587impl From < std:: io:: Error > for ErrorCode {
@@ -116,21 +118,10 @@ impl From<Vec<u8>> for ErrorCode {
116118 }
117119}
118120
119- impl From < PoisonError < MutexGuard < ' _ , HashMap < std:: string:: String , KvsValue > > > > for ErrorCode {
120- fn from ( cause : PoisonError < MutexGuard < ' _ , HashMap < std:: string:: String , KvsValue > > > ) -> Self {
121- eprintln ! ( "error: Mutex locking failed: {cause:#?}" ) ;
122- ErrorCode :: MutexLockFailed
123- }
124- }
125-
126121#[ cfg( test) ]
127122mod error_code_tests {
128123 use crate :: error_code:: ErrorCode ;
129- use crate :: kvs_value:: KvsValue ;
130- use std:: collections:: HashMap ;
131124 use std:: io:: { Error , ErrorKind } ;
132- use std:: sync:: { Arc , Mutex } ;
133- use std:: thread;
134125
135126 #[ test]
136127 fn test_from_io_error_to_file_not_found ( ) {
@@ -165,20 +156,4 @@ mod error_code_tests {
165156 let bytes: Vec < u8 > = vec ! [ ] ;
166157 assert_eq ! ( ErrorCode :: from( bytes) , ErrorCode :: ConversionFailed ) ;
167158 }
168-
169- #[ test]
170- fn test_from_poison_error_mutex_lock_failed ( ) {
171- let mutex: Arc < Mutex < HashMap < String , KvsValue > > > = Arc :: default ( ) ;
172-
173- // test from: https://doc.rust-lang.org/std/sync/struct.PoisonError.html
174- let c_mutex = Arc :: clone ( & mutex) ;
175- let _ = thread:: spawn ( move || {
176- let _unused = c_mutex. lock ( ) . unwrap ( ) ;
177- panic ! ( ) ;
178- } )
179- . join ( ) ;
180-
181- let error = mutex. lock ( ) . unwrap_err ( ) ;
182- assert_eq ! ( ErrorCode :: from( error) , ErrorCode :: MutexLockFailed ) ;
183- }
184159}
0 commit comments