0

I'm using a Template tool https://github.com/noahmorrison/chevron (Mustache Impl)

My issue is that when I run it on powershell and I try to save the result to a file doing:

chevron C:\templates\db.mustache -d C:\temp\db\dev.json | ConvertTo-Xml > .\Process.xml

Note the function prompts an XML

I get the error:

Traceback (most recent call last):
  File "c:\users\kevin.haunstetter\appdata\local\programs\python\python38-32\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\kevin.haunstetter\appdata\local\programs\python\python38-32\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\kevin.haunstetter\AppData\Local\Programs\Python\Python38-32\Scripts\chevron.exe\__main__.py", line 7, in <module>
  File "c:\users\kevin.haunstetter\appdata\local\programs\python\python38-32\lib\site-packages\chevron\main.py", line 84, in cli_main
    sys.stdout.write(main(**args))
  File "c:\users\kevin.haunstetter\appdata\local\programs\python\python38-32\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\ufeff' in position 0: character maps to <undefined>

Any idea?

  • That's a [BOM](https://en.wikipedia.org/wiki/Byte_order_mark), `>` in PowerShell defaults to little-endian UTF16 encoding. What does the original output from `chevron` look like? – Mathias R. Jessen Aug 21 '20 at 16:23
  • It is an XML, sorry I can share it – Kevin Haunstetter Aug 21 '20 at 16:26
  • You don't need `ConvertTo-Xml` if the output from `chevron` is _already_ XML - assign the output from `chevron` to a variable, then [find a way to write a UTF8-encoded file without a BOM](https://stackoverflow.com/questions/5596982/using-powershell-to-write-a-file-in-utf-8-without-the-bom) :) – Mathias R. Jessen Aug 21 '20 at 16:31

0 Answers0