diff --git a/beets/util/confit.py b/beets/util/confit.py index 7d65a4023..e552ba9fd 100644 --- a/beets/util/confit.py +++ b/beets/util/confit.py @@ -36,6 +36,8 @@ CONFIG_FILENAME = 'config.yaml' DEFAULT_FILENAME = 'config_default.yaml' ROOT_NAME = 'root' +YAML_TAB_PROBLEM = "found character '\\t' that cannot start any token" + # Utilities. @@ -81,9 +83,19 @@ class ConfigReadError(ConfigError): def __init__(self, filename, reason=None): self.filename = filename self.reason = reason + message = 'file {0} could not be read'.format(filename) - if reason: + if isinstance(reason, yaml.scanner.ScannerError) and \ + reason.problem == YAML_TAB_PROBLEM: + # Special-case error message for tab indentation in YAML markup. + message += ': found tab character at line {0}, column {1}'.format( + reason.problem_mark.line + 1, + reason.problem_mark.column + 1, + ) + elif reason: + # Generic error message uses exception's message. message += ': {0}'.format(reason) + super(ConfigReadError, self).__init__(message) diff --git a/docs/changelog.rst b/docs/changelog.rst index dbb4173e4..3aa5bf8a9 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -35,6 +35,8 @@ Other new stuff: * :doc:`/plugins/mpdupdate`: Sends an update message whenever *anything* in the database changes---not just when importing. Thanks to Dang Mai Hai. * Fix an error when migrating the ``.beetsstate`` file on Windows. +* A nicer error message is now given when the configuration file contains tabs. + (YAML doesn't like tabs.) 1.1b1 (January 29, 2013) ------------------------ diff --git a/docs/reference/config.rst b/docs/reference/config.rst index e85128f38..e7cb75be3 100644 --- a/docs/reference/config.rst +++ b/docs/reference/config.rst @@ -23,8 +23,9 @@ file will look like this:: key: value foo: bar -If you have questions about more sophisticated syntax, take a look at the -`YAML`_ documentation. +In YAML, you will need to use spaces (not tabs!) to indent some lines. If you +have questions about more sophisticated syntax, take a look at the `YAML`_ +documentation. .. _YAML: http://yaml.org/