mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
config: wrap UnicodeDecodeErrors on load
This commit is contained in:
committed by
Peter Rowlands (변기호)
parent
e556c632b3
commit
4904286307
+4
-1
@@ -176,7 +176,10 @@ class Config(dict):
|
||||
|
||||
if fs.exists(filename):
|
||||
with fs.open(filename) as fobj:
|
||||
conf_obj = ConfigObj(fobj)
|
||||
try:
|
||||
conf_obj = ConfigObj(fobj)
|
||||
except UnicodeDecodeError as exc:
|
||||
raise ConfigError(str(exc)) from exc
|
||||
else:
|
||||
conf_obj = ConfigObj()
|
||||
return _parse_named(_lower_keys(conf_obj.dict()))
|
||||
|
||||
@@ -3,7 +3,7 @@ import textwrap
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.config import Config
|
||||
from dvc.config import Config, ConfigError
|
||||
from dvc.fs import LocalFileSystem
|
||||
|
||||
|
||||
@@ -70,3 +70,14 @@ def test_s3_ssl_verify(tmp_dir, dvc):
|
||||
ssl_verify = /path/to/custom/cabundle.pem
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_load_unicode_error(tmp_dir, dvc, mocker):
|
||||
config = Config(validate=False)
|
||||
mocker.patch(
|
||||
"configobj.ConfigObj",
|
||||
side_effect=UnicodeDecodeError("", b"", 0, 0, ""),
|
||||
)
|
||||
with pytest.raises(ConfigError):
|
||||
with config.edit():
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user