Skip to content

Commit

Permalink
fix(cli): Enable debug before doing auth
Browse files Browse the repository at this point in the history
Authentication issues are currently hard to debug since `--debug` only
has effect after `gl.auth()` has been called.

For example, a 401 error is printed without any details about the actual
HTTP request being sent:

    $ gitlab --debug --server-url https://gitlab.com current-user get
    401: 401 Unauthorized

By moving the call to `gl.enable_debug()` the usual debug logs get
printed before the final error message.

Signed-off-by: Emanuele Aina <emanuele.aina@collabora.com>
  • Loading branch information
em- authored and nejch committed Nov 21, 2022
1 parent d8a657b commit 65abb85
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions gitlab/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,13 @@ def main() -> None:

try:
gl = gitlab.Gitlab.merge_config(vars(options), gitlab_id, config_files)
if debug:
gl.enable_debug()
if gl.private_token or gl.oauth_token:
gl.auth()
except Exception as e:
die(str(e))

if debug:
gl.enable_debug()

gitlab.v4.cli.run(
gl, gitlab_resource, resource_action, args_dict, verbose, output, fields
)

0 comments on commit 65abb85

Please sign in to comment.