GeezerVison is showing github.com — Exit gracefully if config file cannot be decoded (re #735) · pp1992m/bpython@d4a28ef
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: bpython/config.py +13-7Lines changed: 13 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -137,13 +137,19 @@ def loadini(struct, configfile): |
137 | 137 | in iteritems(defaults['keyboard'])) |
138 | 138 |
|
139 | 139 | fill_config_with_default_values(config, defaults) |
140 | | - if not config.read(config_path): |
141 | | - # No config file. If the user has it in the old place then complain |
142 | | - if os.path.isfile(os.path.expanduser('~/.bpython.ini')): |
143 | | - sys.stderr.write("Error: It seems that you have a config file at " |
144 | | - "~/.bpython.ini. Please move your config file to " |
145 | | - "%s\n" % default_config_path()) |
146 | | - sys.exit(1) |
| 140 | + try: |
| 141 | + if not config.read(config_path): |
| 142 | + # No config file. If the user has it in the old place then complain |
| 143 | + if os.path.isfile(os.path.expanduser('~/.bpython.ini')): |
| 144 | + sys.stderr.write("Error: It seems that you have a config file at " |
| 145 | + "~/.bpython.ini. Please move your config file to " |
| 146 | + "%s\n" % default_config_path()) |
| 147 | + sys.exit(1) |
| 148 | + except UnicodeDecodeError as e: |
| 149 | + sys.stderr.write("Error: Unable to parse config file at '{}' due to an " |
| 150 | + "encoding issue. Please make sure to fix the encoding " |
| 151 | + "of the file or remove it and then try again.\n".format(config_path)) |
| 152 | + sys.exit(1) |
147 | 153 |
|
148 | 154 | def get_key_no_doublebind(command): |
149 | 155 | default_commands_to_keys = defaults['keyboard'] |
|