5454DOCS_URL_BASE = "https://airbytehq.github.io/PyAirbyte"
5555DOCS_URL = f"{ DOCS_URL_BASE } /airbyte.html"
5656
57+ VERTICAL_SEPARATOR = "\n " + "-" * 60
58+
5759
5860# Base error class
5961
@@ -68,6 +70,7 @@ class PyAirbyteError(Exception):
6870 log_file : Path | None = None
6971 context : dict [str , Any ] | None = None
7072 message : str | None = None
73+ original_exception : Exception | None = None
7174
7275 def get_message (self ) -> str :
7376 """Return the best description for the exception.
@@ -83,7 +86,15 @@ def get_message(self) -> str:
8386
8487 def __str__ (self ) -> str :
8588 """Return a string representation of the exception."""
86- special_properties = ["message" , "guidance" , "help_url" , "log_text" , "context" , "log_file" ]
89+ special_properties = [
90+ "message" ,
91+ "guidance" ,
92+ "help_url" ,
93+ "log_text" ,
94+ "context" ,
95+ "log_file" ,
96+ "original_exception" ,
97+ ]
8798 display_properties = {
8899 k : v
89100 for k , v in self .__dict__ .items ()
@@ -93,24 +104,32 @@ def __str__(self) -> str:
93104 context_str = "\n " .join (
94105 f"{ str (k ).replace ('_' , ' ' ).title ()} : { v !r} " for k , v in display_properties .items ()
95106 )
96- exception_str = f"{ self .__class__ .__name__ } : { self .get_message ()} \n "
107+ exception_str = (
108+ f"{ self .get_message ()} ({ self .__class__ .__name__ } )"
109+ + VERTICAL_SEPARATOR
110+ + f"\n { self .__class__ .__name__ } : { self .get_message ()} "
111+ )
112+
113+ if self .guidance :
114+ exception_str += f"\n { self .guidance } "
115+
116+ if self .help_url :
117+ exception_str += f"\n More info: { self .help_url } "
118+
97119 if context_str :
98- exception_str += " " + context_str
120+ exception_str += "\n " + context_str
121+
122+ if self .log_file :
123+ exception_str += f"\n Log file: { self .log_file .absolute ()!s} "
99124
100125 if self .log_text :
101126 if isinstance (self .log_text , list ):
102127 self .log_text = "\n " .join (self .log_text )
103128
104129 exception_str += f"\n Log output: \n { indent (self .log_text , ' ' )} "
105130
106- if self .log_file :
107- exception_str += f"\n Log file: { self .log_file .absolute ()!s} "
108-
109- if self .guidance :
110- exception_str += f"\n Suggestion: { self .guidance } "
111-
112- if self .help_url :
113- exception_str += f"\n More info: { self .help_url } "
131+ if self .original_exception :
132+ exception_str += VERTICAL_SEPARATOR + f"\n Caused by: { self .original_exception !s} "
114133
115134 return exception_str
116135
@@ -275,6 +294,8 @@ class AirbyteConnectorError(PyAirbyteError):
275294 def __post_init__ (self ) -> None :
276295 """Set the log file path for the connector."""
277296 self .log_file = self ._get_log_file ()
297+ if not self .guidance and self .log_file :
298+ self .guidance = "Please review the log file for more information."
278299
279300 def _get_log_file (self ) -> Path | None :
280301 """Return the log file path for the connector."""
@@ -306,15 +327,15 @@ class AirbyteConnectorReadError(AirbyteConnectorError):
306327
307328
308329class AirbyteConnectorWriteError (AirbyteConnectorError ):
309- """Error when reading from the connector."""
330+ """Error when writing to the connector."""
310331
311332
312333class AirbyteConnectorSpecFailedError (AirbyteConnectorError ):
313- """Error when reading from the connector."""
334+ """Error when getting spec from the connector."""
314335
315336
316337class AirbyteConnectorDiscoverFailedError (AirbyteConnectorError ):
317- """Error when reading from the connector."""
338+ """Error when running discovery on the connector."""
318339
319340
320341class AirbyteNoDataFromConnectorError (AirbyteConnectorError ):
0 commit comments