summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>2022-09-01 15:32:07 +1200
committerDouglas Bagnall <dbagnall@samba.org>2022-09-06 21:12:36 +0000
commitca7535912b1d0564654a612deed4f002a2382da8 (patch)
tree1afa2fa8822a3031561b4a7569004ec538b83750 /python
parent62fe118e99e6f0f2c9c09101ec0f79283a342171 (diff)
downloadsamba-ca7535912b1d0564654a612deed4f002a2382da8.tar.gz
samba-ca7535912b1d0564654a612deed4f002a2382da8.tar.bz2
samba-ca7535912b1d0564654a612deed4f002a2382da8.zip
samba-tool: avoid traceback for options errors
What option? None yet, but see the next two commits. We use a local reference to optparse.OptionValueError, to save typing and make the eventual switch to argparse easier. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'python')
-rw-r--r--python/samba/getopt.py3
-rw-r--r--python/samba/netcmd/__init__.py9
2 files changed, 10 insertions, 2 deletions
diff --git a/python/samba/getopt.py b/python/samba/getopt.py
index a271cd8a736..4e70998d9d9 100644
--- a/python/samba/getopt.py
+++ b/python/samba/getopt.py
@@ -31,6 +31,9 @@ from samba.credentials import (
import sys
+OptionError = optparse.OptionValueError
+
+
class SambaOptions(optparse.OptionGroup):
"""General Samba-related command line options."""
diff --git a/python/samba/netcmd/__init__.py b/python/samba/netcmd/__init__.py
index 40b9b213f70..b98f8a47fd0 100644
--- a/python/samba/netcmd/__init__.py
+++ b/python/samba/netcmd/__init__.py
@@ -19,7 +19,7 @@
import optparse
import samba
from samba import colour
-from samba.getopt import SambaOption
+from samba.getopt import SambaOption, OptionError
from samba.logger import get_samba_logger
from ldb import LdbError, ERR_INVALID_CREDENTIALS
import sys
@@ -110,7 +110,12 @@ class Command(object):
message = "uncaught exception"
force_traceback = True
- if isinstance(inner_exception, LdbError):
+ if isinstance(e, OptionError):
+ print(evalue, file=self.errf)
+ self.usage()
+ force_traceback = False
+
+ elif isinstance(inner_exception, LdbError):
(ldb_ecode, ldb_emsg) = inner_exception.args
if ldb_ecode == ERR_INVALID_CREDENTIALS:
print("Invalid username or password", file=self.errf)