Improve :set error messages.
This commit is contained in:
parent
54e2cea460
commit
d99f9a3a20
@ -29,6 +29,7 @@ import sys
|
|||||||
import os.path
|
import os.path
|
||||||
import functools
|
import functools
|
||||||
import configparser
|
import configparser
|
||||||
|
import contextlib
|
||||||
import collections
|
import collections
|
||||||
import collections.abc
|
import collections.abc
|
||||||
|
|
||||||
@ -666,6 +667,18 @@ class ConfigManager(QObject):
|
|||||||
newval = val.typ.transform(newval)
|
newval = val.typ.transform(newval)
|
||||||
return newval
|
return newval
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def _handle_config_error(self):
|
||||||
|
"""Catch errors in set_command and raise CommandError."""
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
except (configexc.NoOptionError, configexc.NoSectionError,
|
||||||
|
configexc.ValidationError) as e:
|
||||||
|
raise cmdexc.CommandError("set: {}".format(e))
|
||||||
|
except (configexc.Error, configparser.Error) as e:
|
||||||
|
raise cmdexc.CommandError("set: {} - {}".format(
|
||||||
|
e.__class__.__name__, e))
|
||||||
|
|
||||||
@cmdutils.register(name='set', instance='config', win_id='win_id',
|
@cmdutils.register(name='set', instance='config', win_id='win_id',
|
||||||
completion=[Completion.section, Completion.option,
|
completion=[Completion.section, Completion.option,
|
||||||
Completion.value])
|
Completion.value])
|
||||||
@ -703,7 +716,7 @@ class ConfigManager(QObject):
|
|||||||
option = option[:-1]
|
option = option[:-1]
|
||||||
print_ = True
|
print_ = True
|
||||||
else:
|
else:
|
||||||
try:
|
with self._handle_config_error():
|
||||||
if option.endswith('!') and option != '!' and value is None:
|
if option.endswith('!') and option != '!' and value is None:
|
||||||
option = option[:-1]
|
option = option[:-1]
|
||||||
val = self.get(section_, option)
|
val = self.get(section_, option)
|
||||||
@ -719,16 +732,10 @@ class ConfigManager(QObject):
|
|||||||
else:
|
else:
|
||||||
raise cmdexc.CommandError("set: The following arguments "
|
raise cmdexc.CommandError("set: The following arguments "
|
||||||
"are required: value")
|
"are required: value")
|
||||||
except (configexc.Error, configparser.Error) as e:
|
|
||||||
raise cmdexc.CommandError("set: {} - {}".format(
|
|
||||||
e.__class__.__name__, e))
|
|
||||||
|
|
||||||
if print_:
|
if print_:
|
||||||
try:
|
with self._handle_config_error():
|
||||||
val = self.get(section_, option, transformed=False)
|
val = self.get(section_, option, transformed=False)
|
||||||
except configexc.Error as e:
|
|
||||||
raise cmdexc.CommandError("set: {} - {}".format(
|
|
||||||
e.__class__.__name__, e))
|
|
||||||
message.info(win_id, "{} {} = {}".format(
|
message.info(win_id, "{} {} = {}".format(
|
||||||
section_, option, val), immediately=True)
|
section_, option, val), immediately=True)
|
||||||
|
|
||||||
|
@ -17,11 +17,11 @@ Feature: Setting settings.
|
|||||||
|
|
||||||
Scenario: Invalid section
|
Scenario: Invalid section
|
||||||
When I run :set blah blub foo
|
When I run :set blah blub foo
|
||||||
Then the error "set: NoSectionError - Section 'blah' does not exist!" should be shown.
|
Then the error "set: Section 'blah' does not exist!" should be shown.
|
||||||
|
|
||||||
Scenario: Invalid option
|
Scenario: Invalid option
|
||||||
When I run :set general blub foo
|
When I run :set general blub foo
|
||||||
Then the error "set: NoOptionError - No option 'blub' in section 'general'" should be shown.
|
Then the error "set: No option 'blub' in section 'general'" should be shown.
|
||||||
|
|
||||||
Scenario: Toggling an option
|
Scenario: Toggling an option
|
||||||
When I run :set general auto-save-config false
|
When I run :set general auto-save-config false
|
||||||
@ -46,6 +46,10 @@ Feature: Setting settings.
|
|||||||
And I run :set -p general auto-save-config!
|
And I run :set -p general auto-save-config!
|
||||||
Then the message "general auto-save-config = True" should be shown.
|
Then the message "general auto-save-config = True" should be shown.
|
||||||
|
|
||||||
|
Scenario: Setting an invalid value
|
||||||
|
When I run :set general auto-save-config blah
|
||||||
|
Then the error "set: Invalid value 'blah' - must be a boolean!" should be shown.
|
||||||
|
|
||||||
Scenario: Setting a temporary option
|
Scenario: Setting a temporary option
|
||||||
# We don't actually check if the option is temporary as this isn't easy
|
# We don't actually check if the option is temporary as this isn't easy
|
||||||
# to check.
|
# to check.
|
||||||
@ -74,11 +78,11 @@ Feature: Setting settings.
|
|||||||
|
|
||||||
Scenario: Invalid option with ? (issue 1109)
|
Scenario: Invalid option with ? (issue 1109)
|
||||||
When I run :set general foo?
|
When I run :set general foo?
|
||||||
Then the error "set: NoOptionError - No option 'foo' in section 'general'" should be shown.
|
Then the error "set: No option 'foo' in section 'general'" should be shown.
|
||||||
|
|
||||||
Scenario: Invalid section/option with ? (issue 1109)
|
Scenario: Invalid section/option with ? (issue 1109)
|
||||||
When I run :set blah foo ?
|
When I run :set blah foo ?
|
||||||
Then the error "set: NoSectionError - Section 'blah' does not exist!" should be shown.
|
Then the error "set: Section 'blah' does not exist!" should be shown.
|
||||||
|
|
||||||
Scenario: Empty option with !
|
Scenario: Empty option with !
|
||||||
When I run :set general !
|
When I run :set general !
|
||||||
@ -90,8 +94,8 @@ Feature: Setting settings.
|
|||||||
|
|
||||||
Scenario: Invalid option with !
|
Scenario: Invalid option with !
|
||||||
When I run :set general foo!
|
When I run :set general foo!
|
||||||
Then the error "set: NoOptionError - No option 'foo' in section 'general'" should be shown.
|
Then the error "set: No option 'foo' in section 'general'" should be shown.
|
||||||
|
|
||||||
Scenario: Invalid section/option with !
|
Scenario: Invalid section/option with !
|
||||||
When I run :set blah foo !
|
When I run :set blah foo !
|
||||||
Then the error "set: NoSectionError - Section 'blah' does not exist!" should be shown.
|
Then the error "set: Section 'blah' does not exist!" should be shown.
|
||||||
|
Loading…
Reference in New Issue
Block a user