Commits

Adrian Sampson committed b9289a0

better error message when using real tabs

Comments (0)

Files changed (3)

beets/util/confit.py

 DEFAULT_FILENAME = 'config_default.yaml'
 ROOT_NAME = 'root'
 
+YAML_TAB_PROBLEM = "found character '\\t' that cannot start any token"
+
 
 # Utilities.
 
     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)
 
 

docs/changelog.rst

 * :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)
 ------------------------

docs/reference/config.rst

         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/