hyf

Context-aware query service for Radroots
git clone https://radroots.dev/git/hyf.git
Log | Files | Refs | README | LICENSE

errors.mojo (1343B)


      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 '" + capability + "' is disabled",
     35     )
     36 
     37 
     38 def capability_unavailable_error(capability: String) -> WireError:
     39     return WireError(
     40         code="capability_unavailable",
     41         message="bootstrap capability '" + capability + "' is not implemented yet",
     42     )
     43 
     44 
     45 def internal_error() -> WireError:
     46     return WireError(
     47         code="internal_error", message=internal_error_message()
     48     )