Skip to content

Commit

Permalink
Slight improvements to error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
jimporter committed Mar 25, 2021
1 parent d119286 commit 1b272a0
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 20 deletions.
8 changes: 4 additions & 4 deletions mike/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def delete(versions=None, all=False, *, branch='gh-pages', message=None,
try:
removed = all_versions.difference_update(versions)
except KeyError as e:
raise ValueError('version {} does not exist'.format(e))
raise ValueError('version {!r} does not exist'.format(e))

for i in removed:
if isinstance(i, str):
Expand All @@ -137,7 +137,7 @@ def alias(cfg, version, aliases, update_aliases=False, redirect=True,
try:
real_version = all_versions.find(version, strict=True)[0]
except KeyError as e:
raise ValueError('version {} does not exist'.format(e))
raise ValueError('version {!r} does not exist'.format(e))

if message is None:
message = (
Expand Down Expand Up @@ -190,7 +190,7 @@ def retitle(version, title, *, branch='gh-pages', message=None, prefix=''):
try:
all_versions.update(version, title)
except KeyError:
raise ValueError('version {} does not exist'.format(version))
raise ValueError('version {!r} does not exist'.format(version))

with git_utils.Commit(branch, message) as commit:
commit.add_file(versions_to_file_info(all_versions, prefix))
Expand All @@ -210,7 +210,7 @@ def set_default(version, template=None, *, branch='gh-pages', message=None,

all_versions = list_versions(branch, prefix)
if not all_versions.find(version):
raise ValueError('version {} does not exist'.format(version))
raise ValueError('version {!r} does not exist'.format(version))

t = _redirect_template(template)
with git_utils.Commit(branch, message) as commit:
Expand Down
4 changes: 1 addition & 3 deletions mike/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,4 @@ def main():
try:
return args.func(args)
except Exception as e:
parser.exit(1, '{prog}: {error}\n'.format(
prog=parser.prog, error=str(e)
))
parser.exit(1, 'error: {}\n'.format(str(e)))
4 changes: 2 additions & 2 deletions mike/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _ensure_unique_aliases(self, version, aliases, update_aliases=False):
)
if not update_aliases:
raise ValueError(
'alias {!r} already exists for version {}'
'alias {!r} already exists for version {!r}'
.format(i, str(key[0]))
)
removed_aliases.append(key)
Expand All @@ -109,7 +109,7 @@ def add(self, version, title=None, aliases=[], update_aliases=False):
self._data[v].update(title, aliases)
else:
if self.find(version):
raise ValueError('version {} already exists'.format(version))
raise ValueError('version {!r} already exists'.format(version))
self._data[v] = VersionInfo(version, title, aliases)

# Remove aliases from old versions that we've moved to this version.
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def test_diverged_remote(self):
check_call_silent(['git', 'fetch', 'origin'])

assertOutput(self, ['mike', 'alias', '1.0', 'latest'], output=(
'mike: gh-pages has diverged from origin/gh-pages\n' +
'error: gh-pages has diverged from origin/gh-pages\n' +
' Pass --ignore to ignore this or --rebase to rebase onto ' +
'remote\n'
), returncode=1)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_diverged_remote(self):
check_call_silent(['git', 'fetch', 'origin'])

assertOutput(self, ['mike', 'delete', '1.0'], output=(
'mike: gh-pages has diverged from origin/gh-pages\n' +
'error: gh-pages has diverged from origin/gh-pages\n' +
' Pass --ignore to ignore this or --rebase to rebase onto ' +
'remote\n'
), returncode=1)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def test_diverged_remote(self):
check_call_silent(['git', 'fetch', 'origin'])

assertOutput(self, ['mike', 'deploy', '1.0'], output=(
'mike: gh-pages has diverged from origin/gh-pages\n' +
'error: gh-pages has diverged from origin/gh-pages\n' +
' Pass --ignore to ignore this or --rebase to rebase onto ' +
'remote\n'
), returncode=1)
Expand Down
6 changes: 3 additions & 3 deletions test/integration/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_list_version(self):
self._check_list(['4.0'], '4.0 [dev, latest]\n')
self._check_list(['stable'], '"3.0.3" (3.0) [stable]\n')
self._check_list(['nonexist'], '',
'mike: version nonexist does not exist\n', 1)
'error: version nonexist does not exist\n', 1)

def test_list_json(self):
proc = self._get_list(['-j'])
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_from_subdir(self):
self._check_list(['4.0'] + opts, '4.0 [dev, latest]\n')
self._check_list(['stable'] + opts, '"3.0.3" (3.0) [stable]\n')
self._check_list(['nonexist'] + opts, '',
'mike: version nonexist does not exist\n', 1)
'error: version nonexist does not exist\n', 1)

self._check_list(['1.0', '-b', 'gh-pages', '-r', 'origin'],
'1.0\n')
Expand Down Expand Up @@ -189,4 +189,4 @@ def test_list_version(self):
self._check_list(['4.0'], '4.0 [dev, latest]\n')
self._check_list(['stable'], '"3.0.3" (3.0) [stable]\n')
self._check_list(['nonexist'], '',
'mike: version nonexist does not exist\n', 1)
'error: version nonexist does not exist\n', 1)
2 changes: 1 addition & 1 deletion test/integration/test_retitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_diverged_remote(self):
check_call_silent(['git', 'fetch', 'origin'])

assertOutput(self, ['mike', 'retitle', '1.0', '1.0.1'], output=(
'mike: gh-pages has diverged from origin/gh-pages\n' +
'error: gh-pages has diverged from origin/gh-pages\n' +
' Pass --ignore to ignore this or --rebase to rebase onto ' +
'remote\n'
), returncode=1)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_set_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_diverged_remote(self):
check_call_silent(['git', 'fetch', 'origin'])

assertOutput(self, ['mike', 'set-default', '1.0'], output=(
'mike: gh-pages has diverged from origin/gh-pages\n' +
'error: gh-pages has diverged from origin/gh-pages\n' +
' Pass --ignore to ignore this or --rebase to rebase onto ' +
'remote\n'
), returncode=1)
Expand Down
6 changes: 3 additions & 3 deletions test/unit/test_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_add_update_alias(self):
def test_add_overwrite_alias(self):
versions = Versions()
versions.add('1.0', aliases=['latest'])
msg = r"alias 'latest' already exists for version 1\.0"
msg = r"alias 'latest' already exists for version '1\.0'"
with self.assertRaisesRegex(ValueError, msg):
versions.add('2.0', aliases=['latest'])

Expand All @@ -152,7 +152,7 @@ def test_add_overwrite_version_with_alias(self):
def test_add_overwrite_alias_with_version(self):
versions = Versions()
versions.add('1.0b1', aliases=['1.0'])
msg = r'version 1\.0 already exists'
msg = r"version '1\.0' already exists"
with self.assertRaisesRegex(ValueError, msg):
versions.add('1.0')
with self.assertRaisesRegex(ValueError, msg):
Expand Down Expand Up @@ -213,7 +213,7 @@ def test_update_overwrite_alias_error(self):
versions.add('1.0', '1.0.0', ['latest'])
versions.add('2.0', '2.0.0')

msg = r"alias 'latest' already exists for version 1\.0"
msg = r"alias 'latest' already exists for version '1\.0'"
with self.assertRaisesRegex(ValueError, msg):
versions.update('2.0', aliases=['latest'])

Expand Down

0 comments on commit 1b272a0

Please sign in to comment.