Skip to content

Commit

Permalink
fix: make errors exit 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ook37 committed Jan 10, 2025
1 parent ea9cbad commit bc87699
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_api_data(pkg_name):
response = requests.get(f"https://pacstall.dev/api/packages/{pkg_name}")
if response.status_code != 200:
print(f"Error: Failed to fetch data for package '{pkg_name}'")
return
sys.exit(1)

api_data = response.json()
last_updated = api_data.get("lastUpdatedAt")
Expand Down Expand Up @@ -200,10 +200,10 @@ def alter_package(name, distros, architectures, overflow=5):
missing = 1
print(f"Error: missing 'architectures'")
if (missing == 1):
return
sys.exit(1)
if (overflow < 1):
print(f"Error: 'overflow' must be 1 or greater")
return
sys.exit(1)

if package_exists:
current_data = data[name]
Expand All @@ -215,7 +215,7 @@ def alter_package(name, distros, architectures, overflow=5):
last_updated, available_architectures = get_api_data(name)
except ValueError as e:
print(e)
return
sys.exit(1)

for arch in architectures:
if arch not in available_architectures:
Expand All @@ -242,7 +242,7 @@ def add_command(subparsers, name, aliases, help_text, arguments):
handler = globals().get(f"handle_{name}")
if handler is None:
print(f"Error: No handler defined for command '{name}'")
return
sys.exit(1)
parser = subparsers.add_parser(name, help=f"{help_text} {{aliases: {'|'.join(aliases)}}}")
for arg_name, arg_kwargs in arguments.items():
parser.add_argument(arg_name, **arg_kwargs)
Expand All @@ -261,10 +261,10 @@ def handle_add(args):
if invalid_distros:
print(f"Error: Invalid distros given: {', '.join(invalid_distros)}")
print(f"Valid distros are: {', '.join(valid_distros)}")
return
sys.exit(1)
if 'main' in distros and len(distros) > 1:
print(f"Error: 'main' is mutually exclusive.")
return
sys.exit(1)
else:
distros = None

Expand All @@ -274,10 +274,10 @@ def handle_add(args):
if invalid_architectures:
print(f"Error: Invalid architectures given: {', '.join(invalid_architectures)}")
print(f"Valid architectures are: {', '.join(valid_architectures)}")
return
sys.exit(1)
if ('any' in architectures or 'all' in architectures) and len(architectures) > 1:
print(f"Error: 'any' and 'all' are mutually exclusive.")
return
sys.exit(1)
else:
architectures = None

Expand Down

0 comments on commit bc87699

Please sign in to comment.