@@ -32,6 +32,39 @@ def __init__(
3232 self .core_data : CorePluginData = core_data
3333 self .data : VcpkgData = resolve_vcpkg_data (configuration_data , core_data )
3434
35+ @staticmethod
36+ def _handle_subprocess_error (
37+ logger_instance , operation : str , error : subprocess .CalledProcessError , exception_class : type
38+ ) -> None :
39+ """Handles subprocess errors with comprehensive error message formatting.
40+
41+ Args:
42+ logger_instance: The logger instance to use for error logging
43+ operation: Description of the operation that failed (e.g., 'install', 'clone')
44+ error: The CalledProcessError exception
45+ exception_class: The exception class to raise
46+
47+ Raises:
48+ The specified exception_class with the formatted error message
49+ """
50+ # Capture both stdout and stderr for better error reporting
51+ stdout_msg = error .stdout .strip () if error .stdout else ''
52+ stderr_msg = error .stderr .strip () if error .stderr else ''
53+
54+ # Combine both outputs for comprehensive error message
55+ error_parts = []
56+ if stderr_msg :
57+ error_parts .append (f'stderr: { stderr_msg } ' )
58+ if stdout_msg :
59+ error_parts .append (f'stdout: { stdout_msg } ' )
60+
61+ if not error_parts :
62+ error_parts .append (f'Command failed with exit code { error .returncode } ' )
63+
64+ error_msg = ' | ' .join (error_parts )
65+ logger_instance .error ('Unable to %s: %s' , operation , error_msg , exc_info = True )
66+ raise exception_class ('vcpkg' , operation , error_msg , error ) from error
67+
3568 @staticmethod
3669 def features (directory : Path ) -> SupportedFeatures :
3770 """Queries vcpkg support
@@ -82,6 +115,7 @@ def _update_provider(cls, path: Path) -> None:
82115 shell = True ,
83116 check = True ,
84117 capture_output = True ,
118+ text = True ,
85119 )
86120 elif system_name == 'posix' :
87121 subprocess .run (
@@ -90,11 +124,10 @@ def _update_provider(cls, path: Path) -> None:
90124 shell = True ,
91125 check = True ,
92126 capture_output = True ,
127+ text = True ,
93128 )
94129 except subprocess .CalledProcessError as e :
95- error_msg = e .stderr .decode () if e .stderr else str (e )
96- logger .error ('Unable to bootstrap the vcpkg repository: %s' , error_msg , exc_info = True )
97- raise ProviderToolingError ('vcpkg' , 'bootstrap' , error_msg , e ) from e
130+ cls ._handle_subprocess_error (logger , 'bootstrap the vcpkg repository' , e , ProviderToolingError )
98131
99132 def sync_data (self , consumer : SyncConsumer ) -> SyncData :
100133 """Gathers a data object for the given generator
@@ -125,7 +158,7 @@ def _create_cmake_sync_data(self) -> CMakeSyncData:
125158
126159 return CMakeSyncData (
127160 provider_name = TypeName ('vcpkg' ),
128- toolchain = vcpkg_cmake_path ,
161+ toolchain_file = vcpkg_cmake_path ,
129162 )
130163
131164 @classmethod
@@ -169,17 +202,17 @@ async def download_tooling(cls, directory: Path) -> None:
169202 cwd = directory ,
170203 check = True ,
171204 capture_output = True ,
205+ text = True ,
172206 )
173207 subprocess .run (
174208 ['git' , 'pull' ],
175209 cwd = directory ,
176210 check = True ,
177211 capture_output = True ,
212+ text = True ,
178213 )
179214 except subprocess .CalledProcessError as e :
180- error_msg = e .stderr .decode () if e .stderr else str (e )
181- logger .error ('Unable to update the vcpkg repository: %s' , error_msg , exc_info = True )
182- raise ProviderToolingError ('vcpkg' , 'update' , error_msg , e ) from e
215+ cls ._handle_subprocess_error (logger , 'update the vcpkg repository' , e , ProviderToolingError )
183216 else :
184217 try :
185218 logger .debug ("Cloning the vcpkg repository to '%s'" , directory .absolute ())
@@ -190,12 +223,11 @@ async def download_tooling(cls, directory: Path) -> None:
190223 cwd = directory ,
191224 check = True ,
192225 capture_output = True ,
226+ text = True ,
193227 )
194228
195229 except subprocess .CalledProcessError as e :
196- error_msg = e .stderr .decode () if e .stderr else str (e )
197- logger .error ('Unable to clone the vcpkg repository: %s' , error_msg , exc_info = True )
198- raise ProviderToolingError ('vcpkg' , 'clone' , error_msg , e ) from e
230+ cls ._handle_subprocess_error (logger , 'clone the vcpkg repository' , e , ProviderToolingError )
199231
200232 cls ._update_provider (directory )
201233
@@ -220,11 +252,10 @@ def install(self) -> None:
220252 cwd = str (build_path ),
221253 check = True ,
222254 capture_output = True ,
255+ text = True ,
223256 )
224257 except subprocess .CalledProcessError as e :
225- error_msg = e .stderr .decode () if e .stderr else str (e )
226- logger .error ('Unable to install project dependencies: %s' , error_msg , exc_info = True )
227- raise ProviderInstallationError ('vcpkg' , error_msg , e ) from e
258+ self ._handle_subprocess_error (logger , 'install project dependencies' , e , ProviderInstallationError )
228259
229260 def update (self ) -> None :
230261 """Called when dependencies need to be updated and written to the lock file."""
@@ -248,11 +279,10 @@ def update(self) -> None:
248279 cwd = str (build_path ),
249280 check = True ,
250281 capture_output = True ,
282+ text = True ,
251283 )
252284 except subprocess .CalledProcessError as e :
253- error_msg = e .stderr .decode () if e .stderr else str (e )
254- logger .error ('Unable to update project dependencies: %s' , error_msg , exc_info = True )
255- raise ProviderInstallationError ('vcpkg' , error_msg , e ) from e
285+ self ._handle_subprocess_error (logger , 'update project dependencies' , e , ProviderInstallationError )
256286
257287 def publish (self ) -> None :
258288 """Called when the project needs to be published.
0 commit comments