From dfb128e9210bc8b5783ea7215e846e6adf3be634 Mon Sep 17 00:00:00 2001
From: "Antoine R. Dumont (@ardumont)" <antoine.romain.dumont@gmail.com>
Date: Thu, 21 Jun 2018 10:47:59 +0200
Subject: [PATCH] swh.model.cli: Catch specific exception during identifiers
 check

Related T1104
---
 swh/model/cli.py | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/swh/model/cli.py b/swh/model/cli.py
index 9e0471a4..7d018d6d 100644
--- a/swh/model/cli.py
+++ b/swh/model/cli.py
@@ -9,6 +9,7 @@ import sys
 
 from swh.model import identifiers as pids
 from swh.model.from_disk import Content, Directory
+from swh.model.identifiers import SWHMalformedIdentifierException
 
 
 class PidParamType(click.ParamType):
@@ -16,12 +17,10 @@ class PidParamType(click.ParamType):
 
     def convert(self, value, param, ctx):
         try:
-            _parsed_pid = pids.parse_persistent_identifier(value)  # noqa
+            pids.parse_persistent_identifier(value)
             return value  # return as string, as we need just that
-        except Exception:
-            # TODO catch more specific parsing exception. Requires
-            # https://forge.softwareheritage.org/T1104 to be addressed first.
-            self.fail('%s is not a valid PID' % value, param, ctx)
+        except SWHMalformedIdentifierException as e:
+            self.fail('%s is not a valid PID. %s.' % (value, e), param, ctx)
 
 
 def pid_of_file(path):
-- 
GitLab