Merge lp:~jelmer/brz/patch-strip-non-int into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/patch-strip-non-int
Merge into: lp:brz
Diff against target: 57 lines (+17/-1)
4 files modified
breezy/option.py (+5/-1)
breezy/tests/blackbox/test_patch.py (+6/-0)
breezy/tests/test_options.py (+2/-0)
doc/en/release-notes/brz-3.1.txt (+4/-0)
To merge this branch: bzr merge lp:~jelmer/brz/patch-strip-non-int
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+368870@code.launchpad.net

Commit message

Print sensible error message when an invalid argument is specified for an option.

Description of the change

Print sensible error message when an invalid argument is specified for an option.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/option.py'
2--- breezy/option.py 2018-11-11 04:08:32 +0000
3+++ breezy/option.py 2019-06-15 19:12:19 +0000
4@@ -246,7 +246,11 @@
5 self.custom_callback(option, self._param_name, bool_v, parser)
6
7 def _optparse_callback(self, option, opt, value, parser):
8- v = self.type(value)
9+ try:
10+ v = self.type(value)
11+ except ValueError as e:
12+ raise optparse.OptionValueError(
13+ 'invalid value for option %s: %s' % (option, value))
14 setattr(parser.values, self._param_name, v)
15 if self.custom_callback is not None:
16 self.custom_callback(option, self.name, v, parser)
17
18=== modified file 'breezy/tests/blackbox/test_patch.py'
19--- breezy/tests/blackbox/test_patch.py 2019-04-06 12:46:37 +0000
20+++ breezy/tests/blackbox/test_patch.py 2019-06-15 19:12:19 +0000
21@@ -34,3 +34,9 @@
22 self.assertFileEqual('hello', 'myfile')
23 self.run_bzr('patch -p1 --silent mypatch')
24 self.assertFileEqual('goodbye', 'myfile')
25+
26+ def test_patch_invalid_strip(self):
27+ self.run_bzr_error(
28+ args="patch --strip=a",
29+ error_regexes=[
30+ 'brz: ERROR: invalid value for option -p/--strip: a'])
31
32=== modified file 'breezy/tests/test_options.py'
33--- breezy/tests/test_options.py 2018-11-16 12:32:43 +0000
34+++ breezy/tests/test_options.py 2019-06-15 19:12:19 +0000
35@@ -114,6 +114,8 @@
36 ['--number'])
37 self.assertRaises(errors.BzrCommandError, self.parse, options,
38 ['--no-number'])
39+ self.assertRaises(errors.BzrCommandError, self.parse, options,
40+ ['--number', 'a'])
41
42 def test_is_hidden(self):
43 self.assertTrue(option.Option('foo', hidden=True).is_hidden('foo'))
44
45=== modified file 'doc/en/release-notes/brz-3.1.txt'
46--- doc/en/release-notes/brz-3.1.txt 2019-06-15 13:52:00 +0000
47+++ doc/en/release-notes/brz-3.1.txt 2019-06-15 19:12:19 +0000
48@@ -49,6 +49,10 @@
49 .. Fixes for situations where brz would previously crash or give incorrect
50 or undesirable results.
51
52+* Print a sensible error message when conversion for an option fails
53+ (i.e. when a non-int is specified as the value for an integer
54+ parameter) (#237844, Jelmer Vernooij)
55+
56 Documentation
57 *************
58

Subscribers

People subscribed via source and target branches