about summary refs log tree commit diff
path: root/pkgs/games
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2019-06-10 23:55:49 +0200
committeraszlig <aszlig@nix.build>2019-06-11 00:14:02 +0200
commit921c6c1cb885eb4f64fab61906f81bebc4e5327d (patch)
tree013f63c64707a9bc03dcc9f482b866f9811d1dd8 /pkgs/games
parent09b063b9a67de7f5cdda83f0b04b039f7621060a (diff)
fetch-gog: Provide a better login failure message
So far if the login credentials were wrong, you get something like this:

  Traceback (most recent call last):
    File "/nix/store/...-fetch-gog.py", line 113, in <module>
      GogFetcher(sys.argv[1], sys.argv[2], sys.argv[3]).fetch()
    File "/nix/store/...-fetch-gog.py", line 15, in __init__
      self.login()
    File "/nix/store/...-fetch-gog.py", line 28, in login
      auth_code = parse_qs(urlsplit(browser.get_url()).query)['code']
  KeyError: 'code'

This is isn't very helpful and might hint that there is something wrong
with the fetcher. Of course, if GOG would change their login interface
and no longer expose the "code" query string item, it might still say
login failure, but right now we don't have a better way to detect it.

At least if we get a login failure with a login that has been working so
far, we know something has changed upstream :-)

Signed-off-by: aszlig <aszlig@nix.build>
Reported-by: @Profpatsch
Diffstat (limited to 'pkgs/games')
-rw-r--r--pkgs/games/gog/fetch-gog/default.nix10
1 files changed, 8 insertions, 2 deletions
diff --git a/pkgs/games/gog/fetch-gog/default.nix b/pkgs/games/gog/fetch-gog/default.nix
index b49f0dab..31b4cd38 100644
--- a/pkgs/games/gog/fetch-gog/default.nix
+++ b/pkgs/games/gog/fetch-gog/default.nix
@@ -185,13 +185,19 @@ let
           browser['login[password]'] = ${mkPyStr password}
           browser.submit_selected()
 
-          auth_code = parse_qs(urlsplit(browser.get_url()).query)['code']
+          query = parse_qs(urlsplit(browser.get_url()).query)
+
+          if 'code' not in query:
+            sys.stderr.write(
+              "Unable to login with the provided GOG credentials."
+            )
+            raise SystemExit(1)
 
           token_url = "https://auth.gog.com/token?" + urlencode({
             'client_id': ${mkPyStr clientId},
             'client_secret': ${mkPyStr clientSecret},
             'grant_type': 'authorization_code',
-            'code': auth_code,
+            'code': query['code'],
             'redirect_uri': ${mkPyStr redirectUri}
           })