-
Hello all, I got an template for Discord webhook when the backup fail. However, there're newline (\n) in strerr that breaks the JSON and make it invalid. What can I do the strip it out? Thanks in advance. Data Input [Error]
Stderr = "\rsignal interrupt received, cleaning up\n" Template {
"name": "stderr",
"value": "{{ .Error.Stderr | splitR "\\n" | join "" | replace "\\" "\\\\" }}"
} Aside from {
"name": "stderr",
"value": "
signal interrupt received, cleaning up"
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
That's funny, what you did seems totally correct. E.g. I've extended unit tests to test it and they all succeed: {
template: `{{ "\n\nsignal interrupt received, cleaning up\n\n" | split "\n" | join "" | replace "\\" "\\\\" }}`,
expected: `signal interrupt received, cleaning up`,
},
{
template: `{{ "\n\nsignal interrupt received, cleaning up\n\n" | splitR "\\n" | join "" | replace "\\" "\\\\" }}`,
expected: `signal interrupt received, cleaning up`,
},
{
template: `{{ "\n\nsignal interrupt received, cleaning up\n\n" | js }}`,
expected: `\u000A\u000Asignal interrupt received, cleaning up\u000A\u000A`,
}, One hint I can give however: We didn't document (yet) the standard methods that are available to all go templates. They are just a few but include an encoding method for JS(ON) strings (see last template). Could it be another character (e.g. |
Beta Was this translation helpful? Give feedback.
You're right. I found the input is wrong. I have corrected post up top. The first charater is indeed
\r
not\n
, and there are tons of leading spaces in the output. This is the root cause why the testing passed but not in actual use. However,js
does solve the problem.The actual output by restic via stderr in base64:
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICANc2lnbmFsIGludGVycnVwdCByZWNlaXZlZCwgY2xlYW5pbmcgdXAK