mirror of
https://github.com/platformio/platformio-core.git
synced 2025-08-03 11:54:26 +02:00
Better explanation about encoding error // Resolve #2796
This commit is contained in:
@@ -80,12 +80,14 @@ class InoToCPPConverter(object):
|
||||
assert self._gcc_preprocess(contents, out_file)
|
||||
contents = fs.get_file_contents(out_file)
|
||||
contents = self._join_multiline_strings(contents)
|
||||
fs.write_file_contents(out_file, self.append_prototypes(contents))
|
||||
fs.write_file_contents(
|
||||
out_file, self.append_prototypes(contents), errors="backslashreplace"
|
||||
)
|
||||
return out_file
|
||||
|
||||
def _gcc_preprocess(self, contents, out_file):
|
||||
tmp_path = mkstemp()[1]
|
||||
fs.write_file_contents(tmp_path, contents)
|
||||
fs.write_file_contents(tmp_path, contents, errors="backslashreplace")
|
||||
self.env.Execute(
|
||||
self.env.VerboseAction(
|
||||
'$CXX -o "{0}" -x c++ -fpreprocessed -dD -E "{1}"'.format(
|
||||
|
@@ -58,12 +58,19 @@ def get_file_contents(path):
|
||||
return fp.read()
|
||||
|
||||
|
||||
def write_file_contents(path, contents):
|
||||
def write_file_contents(path, contents, errors=None):
|
||||
try:
|
||||
with open(path, "w") as fp:
|
||||
return fp.write(contents)
|
||||
except UnicodeEncodeError:
|
||||
with io.open(path, "w", encoding="latin-1", errors="backslashreplace") as fp:
|
||||
if errors:
|
||||
click.secho(
|
||||
"Warning! There is a problem with contents encoding, please remove "
|
||||
"invalid characters (non-ASCII or non-UT8) in %s" % path,
|
||||
fg="yellow",
|
||||
err=True,
|
||||
)
|
||||
with io.open(path, "w", encoding="latin-1", errors=errors) as fp:
|
||||
return fp.write(contents)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user