File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44
55[project ]
66name = " koi-net"
7- version = " 1.2.2 "
7+ version = " 1.2.3 "
88description = " Implementation of KOI-net protocol in Python"
99authors = [
1010 {name = " Luke Miller" , email = " luke@block.science" }
@@ -22,7 +22,6 @@ dependencies = [
2222 " cryptography>=45.0.3" ,
2323 " fastapi>=0.115.12" ,
2424 " uvicorn>=0.34.2" ,
25- " rich>=14.1.0" ,
2625 " structlog>=25.4.0" ,
2726]
2827
Original file line number Diff line number Diff line change 44
55import structlog
66
7+ from ..exceptions import BuildError
78from .consts import (
89 COMP_ORDER_OVERRIDE ,
910 COMP_TYPE_OVERRIDE ,
@@ -77,7 +78,7 @@ def build_dependencies(self):
7778
7879 invalid_deps = set (dep_names ) - set (self .comp_dict )
7980 if invalid_deps :
80- raise Exception (f"Dependencies { invalid_deps } of component '{ comp_name } ' are undefined" )
81+ raise BuildError (f"Dependencies { invalid_deps } of component '{ comp_name } ' are undefined" )
8182
8283 self .dep_graph [comp_name ] = dep_names
8384
@@ -125,7 +126,7 @@ def build_init_order(self):
125126
126127 if len (self .init_order ) != len (self .dep_graph ):
127128 cycle_nodes = set (self .dep_graph ) - set (self .init_order )
128- raise Exception (f"Found cycle in dependency graph, the following nodes could not be ordered: { cycle_nodes } " )
129+ raise BuildError (f"Found cycle in dependency graph, the following nodes could not be ordered: { cycle_nodes } " )
129130
130131 log .debug (f"Resolved initialization order: { ' -> ' .join (self .init_order )} " )
131132
Original file line number Diff line number Diff line change 33
44import structlog
55
6+ from ..exceptions import BuildError
67from .artifact import BuildArtifact , CompType
78from .container import NodeContainer
89
@@ -51,7 +52,7 @@ def _build_components(artifact: BuildArtifact):
5152 dependencies = {}
5253 for dep in artifact .dep_graph [comp_name ]:
5354 if dep not in components :
54- raise Exception (f"Couldn't find required component '{ dep } '" )
55+ raise BuildError (f"Couldn't find required component '{ dep } '" )
5556 dependencies [dep ] = components [dep ]
5657 components [comp_name ] = comp (** dependencies )
5758 log .debug ("Done" )
Original file line number Diff line number Diff line change @@ -51,10 +51,10 @@ def save_to_yaml(self):
5151 config_data = self .proxy ._config .model_dump (mode = "json" )
5252 yaml .dump (config_data , f )
5353
54- except Exception as e :
54+ except Exception :
5555 # rewrites original content if YAML dump fails
5656 if self .file_content :
5757 f .seek (0 )
5858 f .truncate ()
5959 f .write (self .file_content )
60- raise e
60+ raise
Original file line number Diff line number Diff line change 1- from koi_net . config .core import NodeConfig
1+ from .core import NodeConfig
22
33
44class ConfigProxy :
@@ -15,6 +15,6 @@ def __init__(self):
1515
1616 def __getattr__ (self , name ):
1717 if not self ._config :
18- raise Exception ("Proxy called before config loaded" )
18+ raise RuntimeError ("Proxy called before config loaded" )
1919
2020 return getattr (self ._config , name )
Original file line number Diff line number Diff line change 77from ..network .response_handler import ResponseHandler
88from ..protocol .model_map import API_MODEL_MAP
99from ..protocol .api_models import ErrorResponse
10- from ..protocol .errors import ProtocolError
10+ from ..protocol .errors import EXCEPTION_TO_ERROR_TYPE , ProtocolError
1111from ..config .full_node import FullNodeConfig
1212
1313log = structlog .stdlib .get_logger ()
@@ -67,7 +67,8 @@ def build_app(self):
6767 def protocol_error_handler (self , request , exc : ProtocolError ):
6868 """Catches `ProtocolError` and returns an `ErrorResponse` payload."""
6969 log .error (exc )
70- resp = ErrorResponse (error = exc .error_type )
70+ resp = ErrorResponse (
71+ error = EXCEPTION_TO_ERROR_TYPE [type (exc )])
7172 log .info (f"Returning error response: { resp } " )
7273 return JSONResponse (
7374 status_code = 400 ,
Original file line number Diff line number Diff line change 1+ # BASE EXCEPTION
2+ class KoiNetError (Exception ):
3+ """Base exception."""
4+ pass
5+
6+ # BUILD ERRORS
7+ class BuildError (KoiNetError ):
8+ """Raised when errors occur in build process."""
9+ pass
10+
11+ # NETWORK REQUEST ERRORS
12+ class RequestError (KoiNetError ):
13+ """Base for network request errors."""
14+ pass
15+
16+ class SelfRequestError (RequestError ):
17+ """Raised when a node tries to request itself."""
18+ pass
19+
20+ class PartialNodeQueryError (RequestError ):
21+ """Raised when attempting to query a partial node."""
22+ pass
23+
24+ class NodeNotFoundError (RequestError ):
25+ """Raised when a node URL cannot be found."""
26+ pass
27+
28+ # PROTOCOL RESPONSE ERRORS
29+ class ProtocolError (KoiNetError ):
30+ """Base for protocol response errors."""
31+ pass
32+
33+ class UnknownNodeError (ProtocolError ):
34+ """Raised when peer node is unknown."""
35+ pass
36+
37+ class InvalidKeyError (ProtocolError ):
38+ """Raised when peer node's public key doesn't match their RID."""
39+ pass
40+
41+ class InvalidSignatureError (ProtocolError ):
42+ """Raised when peer node's envelope signature is invalid."""
43+ pass
44+
45+ class InvalidTargetError (ProtocolError ):
46+ """Raised when peer node's target is not this node."""
47+ pass
Original file line number Diff line number Diff line change 3333log = structlog .stdlib .get_logger ()
3434
3535
36- class KoiNetRequestError (Exception ):
37- pass
38-
39- # Custom error types for request handling
40- class SelfRequestError (KoiNetRequestError ):
41- """Raised when a node tries to request itself."""
42- pass
43-
44- class PartialNodeQueryError (KoiNetRequestError ):
45- """Raised when attempting to query a partial node."""
46- pass
47-
48- class NodeNotFoundError (KoiNetRequestError ):
49- """Raised when a node URL cannot be found."""
50- pass
51-
52- class UnknownPathError (KoiNetRequestError ):
53- """Raised when an unknown path is requested."""
54- pass
55-
5636class RequestHandler :
5737 """Handles making requests to other KOI nodes."""
5838
Original file line number Diff line number Diff line change 11"""Defines KOI-net protocol errors."""
22
33from enum import StrEnum
4+ from ..exceptions import (
5+ ProtocolError ,
6+ UnknownNodeError ,
7+ InvalidKeyError ,
8+ InvalidSignatureError ,
9+ InvalidTargetError
10+ )
411
512
613class ErrorType (StrEnum ):
@@ -9,17 +16,9 @@ class ErrorType(StrEnum):
916 InvalidSignature = "invalid_signature"
1017 InvalidTarget = "invalid_target"
1118
12- class ProtocolError (Exception ):
13- error_type : ErrorType
14-
15- class UnknownNodeError (ProtocolError ):
16- error_type = ErrorType .UnknownNode
17-
18- class InvalidKeyError (ProtocolError ):
19- error_type = ErrorType .InvalidKey
20-
21- class InvalidSignatureError (ProtocolError ):
22- error_type = ErrorType .InvalidSignature
23-
24- class InvalidTargetError (ProtocolError ):
25- error_type = ErrorType .InvalidTarget
19+ EXCEPTION_TO_ERROR_TYPE : dict [ProtocolError , ErrorType ] = {
20+ UnknownNodeError : ErrorType .UnknownNode ,
21+ InvalidKeyError : ErrorType .InvalidKey ,
22+ InvalidSignatureError : ErrorType .InvalidSignature ,
23+ InvalidTargetError : ErrorType .InvalidTarget
24+ }
Original file line number Diff line number Diff line change 1010from .protocol .event import EventType
1111from .protocol .node import NodeProfile
1212from .protocol .secure import PrivateKey
13- from .protocol . errors import (
13+ from .exceptions import (
1414 UnknownNodeError ,
1515 InvalidKeyError ,
1616 InvalidSignatureError ,
You can’t perform that action at this time.
0 commit comments