Skip to content

Commit 665c5a8

Browse files
authored
Bugfix/windows unicode with pipes (#338)
* add handling of UnicodeEncodeError * use explicit newlines so on Windows it doesn't get doubled * output real unicode in json * clarify error message * update error msg again
1 parent c22ce9b commit 665c5a8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/code42cli/click_ext/groups.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import difflib
2+
import platform
23
import re
34
from collections import OrderedDict
45

@@ -100,6 +101,15 @@ def invoke(self, ctx):
100101
self.logger.log_verbose_error(self._original_args, err.response.request)
101102
raise LoggedCLIError("Problem making request to server.")
102103

104+
except UnicodeEncodeError:
105+
if platform.system() == "Windows":
106+
cmd = '$ENV:PYTHONIOENCODING="utf-16"'
107+
else:
108+
cmd = 'export PYTHONIOENCODING="utf-8"'
109+
raise Code42CLIError(
110+
f"Failed to handle unicode character using environment's detected encoding, try running:\n\n {cmd}\n\nand then re-run your `code42` command."
111+
)
112+
103113
except OSError:
104114
raise
105115

src/code42cli/output_formats.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def get_formatted_output(self, df, **kwargs):
9696
"orient": "records",
9797
"lines": True,
9898
"index": True,
99+
"force_ascii": False,
99100
"default_handler": str,
100101
}
101102
defaults.update(kwargs)
@@ -106,13 +107,14 @@ def get_formatted_output(self, df, **kwargs):
106107
"orient": "records",
107108
"lines": False,
108109
"index": True,
110+
"force_ascii": False,
109111
"default_handler": str,
110112
}
111113
defaults.update(kwargs)
112114
return df.to_json(**defaults)
113115

114116
elif self.output_format == OutputFormat.CSV:
115-
defaults = {"index": False}
117+
defaults = {"index": False, "line_terminator": "\n"}
116118
defaults.update(kwargs)
117119
df = df.fillna("")
118120
return df.to_csv(**defaults)

0 commit comments

Comments
 (0)