From: Michael Tremer Date: Mon, 5 Jan 2026 10:13:21 +0000 (+0000) Subject: dnsbl: Gracefully terminate if we could not find a list X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86f9df574d23d8d926e30df7dfb35532a49d7f4b;p=dbl.git dnsbl: Gracefully terminate if we could not find a list Signed-off-by: Michael Tremer --- diff --git a/src/scripts/dnsbl.in b/src/scripts/dnsbl.in index 8edcab2..54e7e7e 100644 --- a/src/scripts/dnsbl.in +++ b/src/scripts/dnsbl.in @@ -236,6 +236,20 @@ class CLI(object): # Otherwise just exit sys.exit(0) + def __get_list(self, backend, slug): + """ + Fetches a list or terminates the program if we could not find the list. + """ + # Fetch the list + list = backend.lists.get_by_slug(slug) + + # Terminate because we could not find the list + if not list: + sys.stderr.write("Could not find list '%s'\n" % slug) + raise SystemExit(2) + + return list + def __list(self, backend, args): table = rich.table.Table(title=_("Lists")) table.add_column(_("Name")) @@ -272,7 +286,7 @@ class CLI(object): """ Deletes a list """ - list = backend.lists.get_by_slug(args.list) + list = self.__get_list(backend, args.list) # Delete! list.delete( @@ -283,7 +297,7 @@ class CLI(object): """ Shows information about a list """ - list = backend.lists.get_by_slug(args.list) + list = self.__get_list(backend, args.list) table = rich.table.Table(title=list.name) table.add_column(_("Property")) @@ -330,7 +344,7 @@ class CLI(object): Updates a single list """ # Fetch the list - list = backend.lists.get_by_slug(args.list) + list = self.__get_list(backend, args.list) # Update! list.update(force=args.force) @@ -347,7 +361,7 @@ class CLI(object): Exports a list """ # Fetch the list - list = backend.lists.get_by_slug(args.list) + list = self.__get_list(backend, args.list) # Export! list.export(args.output, format=args.format) @@ -423,7 +437,7 @@ class CLI(object): Adds a new source to a list """ # Fetch the list - list = backend.lists.get_by_slug(args.list) + list = self.__get_list(backend, args.list) # Create the source backend.sources.create( @@ -439,7 +453,7 @@ class CLI(object): Removes a source from a list """ # Fetch the list - list = backend.lists.get_by_slug(args.list) + list = self.__get_list(backend, args.list) # Remove the source list.delete_source( @@ -490,7 +504,7 @@ class CLI(object): Analyzes a list """ # Fetch the list - list = backend.lists.get_by_slug(args.list) + list = self.__get_list(backend, args.list) # Show duplicates self.__analyze_duplicates(list) @@ -542,7 +556,7 @@ class CLI(object): Shows the history of a list """ # Fetch the list - list = backend.lists.get_by_slug(args.list) + list = self.__get_list(backend, args.list) # Fetch the history history = list.get_history(limit=args.limit)