1 import Base 2 import ./DurableError.bend as DurableError 3 4 # Recognizes the host errno values for lock contention. 5 def busy_code(+code: U32) -> Bool: 6 U32.is_eq(code, 11) || U32.is_eq(code, 35) 7 8 # Recognizes the host errno for a missing path. 9 def missing_code(+code: U32) -> Bool: 10 U32.is_eq(code, 2) 11 12 # Maps non-contention lock errors to NotFound or Io. 13 def classify_nonbusy_lock_error( 14 missing: Bool, 15 code: U32, 16 message: String, 17 operation: String, 18 path: String, 19 ) -> DurableError.Error: 20 match missing: 21 case True{}: 22 DurableError.Error{DurableError.NotFound{}, operation, path, code, message} 23 case False{}: 24 DurableError.Error{DurableError.Io{}, operation, path, code, message} 25 26 # Maps contention to Busy and retains host details. 27 def classify_lock_busy(busy: Bool, +code: U32, message: String, operation: String, path: String) -> DurableError.Error: 28 match busy: 29 case True{}: 30 DurableError.Error{DurableError.Busy{}, operation, path, code, message} 31 case False{}: 32 classify_nonbusy_lock_error(missing_code(code), code, message, operation, path) 33 34 # Maps lock errors using the pure platform policy. 35 def classify_lock_error(+code: U32, message: String, operation: String, path: String) -> DurableError.Error: 36 classify_lock_busy(busy_code(code), code, message, operation, path)