Skip to content

Commit 722dace

Browse files
author
Hugo Osvaldo Barrera
authored
Merge pull request #904 from pimutils/improve-error-msg
Fix double-use of a generator
2 parents c254b4a + 72618e3 commit 722dace

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

vdirsyncer/cli/fetchparams.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,21 @@ def _fetch_value(opts, key):
7474
return rv
7575

7676

77-
def _strategy_command(*command):
77+
def _strategy_command(*command: str):
78+
"""Execute a user-specified command and return its output."""
7879
import subprocess
7980

80-
# normalize path of every path member
81-
# if there is no path specified then nothing will happen
82-
command = map(expand_path, command)
81+
# Normalize path of every path member.
82+
# If there is no path specified then nothing will happen.
83+
# Makes this a list to avoid it being exhausted on the first iteration.
84+
expanded_command = list(map(expand_path, command))
8385

8486
try:
85-
stdout = subprocess.check_output(command, universal_newlines=True)
87+
stdout = subprocess.check_output(expanded_command, universal_newlines=True)
8688
return stdout.strip("\n")
8789
except OSError as e:
88-
raise exceptions.UserError(
89-
"Failed to execute command: {}\n{}".format(" ".join(command), str(e))
90-
)
90+
cmd = " ".join(expanded_command)
91+
raise exceptions.UserError(f"Failed to execute command: {cmd}\n{str(e)}")
9192

9293

9394
def _strategy_prompt(text):

vdirsyncer/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
_missing = object()
2020

2121

22-
def expand_path(p):
22+
def expand_path(p: str) -> str:
23+
"""Expand $HOME in a path and normalise slashes."""
2324
p = os.path.expanduser(p)
2425
p = os.path.normpath(p)
2526
return p

0 commit comments

Comments
 (0)