Skip to content

Commit

Permalink
fix: Print warning when connection to remote fails
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Feb 20, 2019
1 parent 024f1f8 commit 57287fb
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/aria2p/cli.py
Expand Up @@ -19,6 +19,7 @@
import json
import sys

import requests
from aria2p import Download

from .api import API
Expand All @@ -35,6 +36,17 @@ def main(args=None):

api = API(Client(host=kwargs.pop("host"), port=kwargs.pop("port"), secret=kwargs.pop("secret")))

# Warn if no aria2 daemon process seems to be running
try:
api.client.get_version()
except requests.ConnectionError as e:
print(f"[ERROR] {e}", file=sys.stderr)
print(file=sys.stderr)
print("Please make sure that an instance of aria2c is running with RPC mode enabled,", file=sys.stderr)
print("and that you have provided the right host, port and secret token.", file=sys.stderr)
print("More information at https://aria2p.readthedocs.io/en/latest.", file=sys.stderr)
return 2

subcommands = {
None: subcommand_show,
"show": subcommand_show,
Expand Down Expand Up @@ -214,7 +226,9 @@ def subcommand_show(api):
def subcommand_call(api, method, params):
method = get_method(method)
if method is None:
print(f"Unknown method {method}. Run '{sys.argv[0]} -m listmethods' to list the available methods.")
print(f"[ERROR] call: Unknown method {method}.", file=sys.stderr)
print(file=sys.stderr)
print("Run '{sys.argv[0]} -m listmethods' to list the available methods.", file=sys.stderr)
return 1

if isinstance(params, str):
Expand Down

0 comments on commit 57287fb

Please sign in to comment.