Skip to content

Commit 58f3245

Browse files
authored
Add error handling when parsing package locally (#1108)
* Add error handling when parsing package locally Signed-off-by: mini-1235 <[email protected]> * Format Signed-off-by: mini-1235 <[email protected]> --------- Signed-off-by: mini-1235 <[email protected]>
1 parent 8653a5d commit 58f3245

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ros2doctor/ros2doctor/api/package.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,15 @@ def get_local_package_versions() -> dict:
8383
if package_name_prefixes:
8484
for name, prefix in package_name_prefixes.items():
8585
file_path = os.path.join(prefix, 'share', name)
86-
package_obj = parse_package(file_path)
87-
local_packages[name] = package_obj.version if package_obj.version else ''
86+
try:
87+
package_obj = parse_package(file_path)
88+
local_packages[name] = package_obj.version if package_obj.version else ''
89+
except IOError as e:
90+
print(f'Warning: Could not read package at {file_path}: {e}')
91+
local_packages[name] = ''
92+
except Exception as e:
93+
print(f'Error parsing {file_path}: {e}')
94+
local_packages[name] = ''
8895
return local_packages
8996

9097

0 commit comments

Comments
 (0)