Bug 17708 – Escape control characters in std.conv.to error messages

Status
NEW
Severity
minor
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-07-31T19:31:51Z
Last change time
2024-12-01T16:30:39Z
Assigned to
No Owner
Creator
Vladimir Panteleev
See also
https://issues.dlang.org/show_bug.cgi?id=12260
Moved to GitHub: phobos#10259 →

Comments

Comment #0 by dlang-bugzilla — 2017-07-31T19:31:51Z
Currently this program: ///// test.d //// import std.conv; void main() { to!int("\r"); } ///////////////// will produce output which looks like this in a terminal: ' when converting from type string to type intbin/../phobos/std/conv.d(2168): Unexpected ' ---------------- ??:? pure @safe int std.conv.parse!(int, immutable(char)[]).parse(ref immutable(char)[]) [0x4331de] ??:? pure @safe int std.conv.toImpl!(int, immutable(char)[]).toImpl(immutable(char)[]) [0x436a70] ??:? pure @safe int std.conv.to!(int).to!(immutable(char)[]).to(immutable(char)[]) [0x432a83] ??:? _Dmain [0x432a5d] The error message appears malformed. std.conv.to should escape whitespace / control / non-printable characters in its error messages. Perhaps the existing functionality in std.conv / std.format can be reused: format!"%(%s%)"(c.only) will already correctly escape such characters. See discussion in https://github.com/dlang/phobos/pull/5591 (which fixed this issue specifically for the newline character only) for more details.
Comment #1 by jrdemail2000-dlang — 2017-12-17T18:50:54Z
Encountered this case in my tools (https://github.com/eBay/tsv-utils-dlang/issues/96). A user was processing a DOS file (with `\r\n` line endings) on a Unix box, byLine left the extraneous `\r` at the end of the line. My tool tried to convert to double, and output the error text when this failed due to the `\r`. The formatting of the output is quite confusing, as `\r` actually repositions to the start of the line, effectively deleting the initial part of the output line. The result: ' when converting from type const(char)[] to type doubleUnexpected ' For my tools I'll add explicit detection of DOS line endings on Unix boxes, it's just too common when getting data files from a variety of sources. However, it'd be helpful to update error message generation to handle `\r` and other non-printing characters.
Comment #2 by bugzilla — 2019-12-06T13:10:56Z
Which controll characters need escaping? 0x00 - 0x1F only? Or are there more of them I'm unaware of?
Comment #3 by robert.schadek — 2024-12-01T16:30:39Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10259 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB