mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-06 17:22:49 +01:00
Add exception handling for docker API error to so-docker-prune
This commit is contained in:
@@ -38,7 +38,7 @@ def get_image_version(string) -> str:
|
|||||||
Version(ver)
|
Version(ver)
|
||||||
except InvalidVersion:
|
except InvalidVersion:
|
||||||
# Strip the last substring following a hyphen for automated branches
|
# Strip the last substring following a hyphen for automated branches
|
||||||
ver = '-'.join(ver.split('-')[:-1])
|
ver = '-'.join(ver.split('-')[:-1])
|
||||||
return ver
|
return ver
|
||||||
|
|
||||||
|
|
||||||
@@ -73,8 +73,12 @@ def main(quiet):
|
|||||||
for tag in group:
|
for tag in group:
|
||||||
if not quiet: print(f'Removing image {tag}')
|
if not quiet: print(f'Removing image {tag}')
|
||||||
client.images.remove(tag)
|
client.images.remove(tag)
|
||||||
except InvalidVersion as e:
|
except (docker.errors.APIError, InvalidVersion) as e:
|
||||||
print(f'so-{get_so_image_basename(t_list[0])}: {e.args[0]}', file=sys.stderr)
|
print(f'so-{get_so_image_basename(t_list[0])}: {e}', file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print('Unhandled exception occurred:')
|
||||||
|
print(f'so-{get_so_image_basename(t_list[0])}: {e}', file=sys.stderr)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if no_prunable and not quiet:
|
if no_prunable and not quiet:
|
||||||
@@ -86,4 +90,4 @@ if __name__ == "__main__":
|
|||||||
main_parser.add_argument('-q', '--quiet', action='store_const', const=True, required=False)
|
main_parser.add_argument('-q', '--quiet', action='store_const', const=True, required=False)
|
||||||
args = main_parser.parse_args(sys.argv[1:])
|
args = main_parser.parse_args(sys.argv[1:])
|
||||||
|
|
||||||
main(args.quiet)
|
main(args.quiet)
|
||||||
|
|||||||
Reference in New Issue
Block a user