Skip to content

Commit

Permalink
Replace legacy error handling with exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
logandhillon committed Jul 12, 2024
1 parent d640cee commit 02a7bdf
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions bdsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,20 @@ def cmd_ld(self, args):
items = os.listdir(dir)
self.print('\t'.join([item + '/' if os.path.isdir(os.path.join(dir, item)) else item for item in items]))
except FileNotFoundError:
self.print(f"{args[0]}: {args[1]}: does not exist")
raise FileNotFoundError(f"{args[1]}: does not exist")

def cmd_def(self, args):
if '-h' in args or '--help' in args:
self.print(f"usage: def <keyword> <definition>{nl}binds <keyword> to <definition>{nl}executing <keyword> will execute <definition>")
return

if len(args) < 3:
self.print(f"def: missing params (at least 3)")
return
raise ValueError("missing params (at least 3)")

definition = " ".join(args[2:])

if args[1] == definition:
self.print(f"def: keyword cannot be the same as the definition")
return
raise SyntaxError("keyword cannot be the same as the definition")

self.definitions[args[1]] = definition
self.print(f"defined '{args[1]}' to run '{definition}'")
Expand Down

0 comments on commit 02a7bdf

Please sign in to comment.