errors.mojo (1361B)
1 from json import Value, loads 2 3 4 @fieldwise_init 5 struct WireError(Copyable, Movable): 6 var code: String 7 var message: String 8 9 def to_json_value(self) raises -> Value: 10 var value = loads("{}") 11 value.set("code", Value(String(self.code))) 12 value.set("message", Value(String(self.message))) 13 return value^ 14 15 16 def internal_error_message() -> String: 17 return "internal hyf daemon error; inspect local diagnostics" 18 19 20 def invalid_request_error(message: String) -> WireError: 21 return WireError(code="invalid_request", message=message) 22 23 24 def unsupported_capability_error(capability: String) -> WireError: 25 return WireError( 26 code="unsupported_capability", 27 message="no handler registered for capability '" + capability + "'", 28 ) 29 30 31 def capability_disabled_error(capability: String) -> WireError: 32 return WireError( 33 code="capability_disabled", 34 message="bootstrap deferred capability '" 35 + capability 36 + "' is disabled", 37 ) 38 39 40 def capability_unavailable_error(capability: String) -> WireError: 41 return WireError( 42 code="capability_unavailable", 43 message="bootstrap capability '" 44 + capability 45 + "' is not implemented yet", 46 ) 47 48 49 def internal_error() -> WireError: 50 return WireError(code="internal_error", message=internal_error_message())