@@ -20,9 +20,7 @@ class UnknownCLIError(Exception):
2020
2121
2222class CLINotFoundInPathError (Exception ):
23- """
24- Exception raised if the specified CLI binary is not found in the path.
25- """
23+ """Exception raised if the specified CLI binary isn't found in the path."""
2624
2725 def __init__ (self , message = "The CLI binary was not found in the path" , binary = None ):
2826 """Initialize the exception."""
@@ -51,14 +49,12 @@ class EthereumCLI:
5149 cached_version : Optional [str ] = None
5250
5351 def __init__ (self , * , binary : Optional [Path ] = None ):
54- """
55- Abstract initialization method that all subclasses must implement.
56- """
52+ """Abstract init method that all subclasses must implement."""
5753 if binary is None :
5854 binary = self .default_binary
5955 else :
60- # improve behavior of which by resolving the path: ~/relative paths
61- # don't work
56+ # improve behavior of which by resolving the path:
57+ # ~/relative paths don't work
6258 resolved_path = Path (os .path .expanduser (binary )).resolve ()
6359 if resolved_path .exists ():
6460 binary = resolved_path
@@ -80,12 +76,12 @@ def set_default_tool(cls, tool_subclass: Type[Any]):
8076 @classmethod
8177 def from_binary_path (cls , * , binary_path : Optional [Path ], ** kwargs ) -> Any :
8278 """
83- Instantiate the appropriate CLI subclass derived from the CLI's
84- `binary_path`.
79+ Instantiate the appropriate CLI subclass derived from the
80+ CLI's `binary_path`.
8581
86- This method will attempt to detect the CLI version and instantiate the
87- appropriate subclass based on the version output by running the CLI
88- with the version flag.
82+ This method will attempt to detect the CLI version and instantiate
83+ the appropriate subclass based on the version output by running
84+ the CLI with the version flag.
8985 """
9086 assert cls .default_tool is not None , "default CLI implementation was never set"
9187
@@ -127,27 +123,34 @@ def from_binary_path(cls, *, binary_path: Optional[Path], **kwargs) -> Any:
127123 cls .registered_tools , key = lambda x : x .version_flag
128124 ):
129125 logger .debug (
130- f"Trying this `version` flag to determine if t8n supported: { version_flag } "
126+ f"\n { '-' * 120 } \n Trying this `version` flag to determine "
127+ f"if t8n supported: { version_flag } "
131128 )
132129 # adding more logging reveals we check for `-v` twice..
133130
134131 try :
135132 result = subprocess .run (
136- [binary , version_flag ], stdout = subprocess .PIPE , stderr = subprocess .PIPE
133+ [binary , version_flag ],
134+ stdout = subprocess .PIPE ,
135+ stderr = subprocess .PIPE ,
137136 )
138137 logger .debug (
139- f"Subprocess:\n \t stdout: { result .stdout } \n \n \n \t stderr: { result .stderr } \n \n \n " # type: ignore
138+ f"Subprocess:\n \t stdout: { result .stdout } \n \n \n \t " # type: ignore
139+ f"stderr: { result .stderr } \n \n \n " # type: ignore
140140 )
141141
142142 if result .returncode != 0 :
143- logger .debug (f"Subprocess returncode is not 0! It is: { result .returncode } " )
143+ logger .debug (f"Subprocess returncode is not 0!It is: { result .returncode } " )
144+ # don't raise exception, you are supposed to keep trying
145+ # different version flags
144146 continue
145- # don't raise exception, you are supposed to keep
146- # trying different version flags
147147
148+ # if there is a breaking error try sth else
148149 if result .stderr :
149- logger .debug (f"Stderr detected: { result .stderr } " ) # type: ignore
150- continue
150+ stderr_str = str (result .stderr )
151+ if EthereumCLI .stderr_is_breaking (stderr = stderr_str ):
152+ logger .debug (f"Stderr detected: { stderr_str } " )
153+ continue
151154
152155 binary_output = ""
153156 if result .stdout :
@@ -156,9 +159,13 @@ def from_binary_path(cls, *, binary_path: Optional[Path], **kwargs) -> Any:
156159
157160 for subclass in subclasses :
158161 logger .debug (f"Trying subclass { subclass } " )
159-
160- if subclass .detect_binary (binary_output ):
161- return subclass (binary = binary , ** kwargs )
162+ try :
163+ if subclass .detect_binary (binary_output ):
164+ subclass_check_result = subclass (binary = binary , ** kwargs )
165+ return subclass_check_result
166+ except Exception as e :
167+ print (e )
168+ continue
162169
163170 logger .debug (
164171 f"T8n with version { binary_output } does not belong to subclass { subclass } "
@@ -175,12 +182,19 @@ def from_binary_path(cls, *, binary_path: Optional[Path], **kwargs) -> Any:
175182 @classmethod
176183 def detect_binary (cls , binary_output : str ) -> bool :
177184 """
178- Return True if a CLI's `binary_output` matches the class's expected
179- output.
185+ Return True if a CLI's `binary_output` matches the
186+ class's expected output.
180187 """
188+ logger .debug (f"Trying to detect binary for { binary_output } .." )
181189 assert cls .detect_binary_pattern is not None
182190
183- return cls .detect_binary_pattern .match (binary_output ) is not None
191+ logger .debug (
192+ f"Trying to match { binary_output } against this pattern: { cls .detect_binary_pattern } "
193+ )
194+ match_result = cls .detect_binary_pattern .match (binary_output )
195+ match_successful : bool = match_result is not None
196+
197+ return match_successful
184198
185199 @classmethod
186200 def is_installed (cls , binary_path : Optional [Path ] = None ) -> bool :
@@ -194,10 +208,22 @@ def is_installed(cls, binary_path: Optional[Path] = None) -> bool:
194208 binary = shutil .which (binary_path )
195209 return binary is not None
196210
211+ @classmethod
212+ def stderr_is_breaking (cls , * , stderr : str ) -> bool :
213+ """
214+ Process the stderr output and decide if the error is a
215+ breaking error for this specific tool.
216+ """
217+ # harmless java warning on certain systems (besu)
218+ if "SVE vector length" in stderr :
219+ return False
220+
221+ return True
222+
197223 def version (self ) -> str :
198224 """
199- Return the name and version of the CLI as reported by the CLI's version
200- flag.
225+ Return the name and version of the CLI as reported by
226+ the CLI's version flag.
201227 """
202228 if self .cached_version is None :
203229 result = subprocess .run (
0 commit comments