agent: print error message character in hex form if it's unprintable
Summary
Currently, when the agent manager is sent a registration request containing UTF-8 characters, it will form an invalid error message using only one of the bytes from the UTF-8 sequence, which causes an assertion in glib to fail, which replaces the returned error message with "[Invalid UTF-8]". It will also print an assertion failure to the console, or crash NetworkManager on non-release builds.
Purpose
This commit makes it so that it instead prints out the character in hexadecimal form if it isn't normally printable, so that it is once again a valid UTF-8 string.
Checklist
Please read https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/main/CONTRIBUTING.md before opening the merge request. In particular, check that:
-
the subject for all commits is concise and explicative -
the message for all commits explains the reason for the change -
the source is properly formatted -
any relevant documentation is up to date -
you have added unit tests if applicable -
the NEWS file is updated when the change deserves to be mentioned, for example for new features, behavior changes, API deprecations, etc.