cmds.projects.CmdListRepos: Beautify error logging

Call run_curl() with parse_json=True to make that explicit, and be a
little more verbose about the outcome.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-04-07 12:44:05 +02:00
commit 98ad7442d9

View file

@ -55,7 +55,7 @@ class CmdListRepos(Cmd): # export
cmd_input = (f'-u {username}:{password}').encode('utf-8') cmd_input = (f'-u {username}:{password}').encode('utf-8')
curl_args.extend(['-K-']) curl_args.extend(['-K-'])
curl_args.append(f'https://api.github.com/users/{args.from_owner}/repos') curl_args.append(f'https://api.github.com/users/{args.from_owner}/repos')
repos, stderr, status = await run_curl(curl_args, cmd_input=cmd_input) repos, stderr, status = await run_curl(curl_args, cmd_input=cmd_input, parse_json=True)
for repo in repos: for repo in repos:
print(repo['name']) print(repo['name'])
return return
@ -71,12 +71,18 @@ class CmdListRepos(Cmd): # export
api_url = f'{args.base_url}/api/v1/{entities_dir}/{args.from_owner}/repos' api_url = f'{args.base_url}/api/v1/{entities_dir}/{args.from_owner}/repos'
try: try:
tried.append(api_url) tried.append(api_url)
repos, stderr, status = await run_curl(curl_args + [api_url], cmd_input=cmd_input) repos, stderr, status = await run_curl(curl_args + [api_url], cmd_input=cmd_input, parse_json=True)
for repo in repos: for repo in repos:
print(repo['name']) print(repo['name'])
break break
except Exception as e: except Exception as e:
pass msg = 'curl {} failed ({}), trying next'.format(
' '.join(curl_args + [api_url]),
str(e)
)
log(DEBUG, msg)
tried[-1] += ': ' + msg
raise
else: else:
raise RuntimeError(f'Failed to fetch repository list from assumed Forgejo instance at {args.base_url}, tried {', '.join(tried)}') raise RuntimeError(f'Failed to fetch repository list from assumed Forgejo instance at {args.base_url}, tried {', '.join(tried)}')
return return