@@ -121,7 +121,10 @@ def parse_request() -> dict[str, str]:
121121 continue
122122
123123 parts = line .split ("=" , 1 )
124- assert len (parts ) == 2
124+ if len (parts ) != 2 :
125+ raise ValueError (
126+ f"Missing '=' in request line, cannot be parsed as key/value pair: '{ line } '"
127+ )
125128 request [parts [0 ].strip ()] = parts [1 ].strip ()
126129
127130 return request
@@ -494,8 +497,12 @@ def main(argv: Optional[Sequence[str]] = None) -> None:
494497 handle_skip ()
495498
496499 action = args .action
500+ if action != "get" :
501+ LOGGER .info ("Action '%s' is currently not supported" , action )
502+ sys .exit (5 )
503+
497504 request = parse_request ()
498- LOGGER .debug ("Received action %s with request:\n %s" , action , request )
505+ LOGGER .debug ("Received action '%s' with request:\n %s" , action , request )
499506
500507 try :
501508 mapping = parse_mapping (args .mapping )
@@ -504,15 +511,14 @@ def main(argv: Optional[Sequence[str]] = None) -> None:
504511 print (f"Unable to parse mapping file: { error } " , file = sys .stderr ) # noqa: T201
505512 sys .exit (4 )
506513
507- if action == "get" :
508- try :
509- get_password (request , mapping )
510- except Exception as error : # ok'ish for the main function
511- print (f"Unable to retrieve entry: { error } " , file = sys .stderr ) # noqa: T201
512- sys .exit (3 ) # 1: uncaught exceptions, 2: already used by argparse
513- else :
514- LOGGER .info ("Action %s is currently not supported" , action )
515- sys .exit (5 )
514+ try :
515+ get_password (request , mapping )
516+ except Exception as error : # ok'ish for the main function
517+ print ( # noqa: T201
518+ f'Unable to retrieve entry: "{ type (error ).__name__ } : { error } "' ,
519+ file = sys .stderr ,
520+ )
521+ sys .exit (3 ) # 1: uncaught exceptions, 2: already used by argparse
516522
517523
518524if __name__ == "__main__" :
0 commit comments