Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape control characters in std.conv.to error messages #10259

Open
dlangBugzillaToGithub opened this issue Jul 31, 2017 · 2 comments
Open

Escape control characters in std.conv.to error messages #10259

dlangBugzillaToGithub opened this issue Jul 31, 2017 · 2 comments

Comments

@dlangBugzillaToGithub
Copy link

dlang-bugzilla (@CyberShadow) reported this on 2017-07-31T19:31:51Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=17708

CC List

Description

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.
@dlangBugzillaToGithub
Copy link
Author

jrdemail2000-dlang commented on 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.

@dlangBugzillaToGithub
Copy link
Author

bugzilla (@WalterBright) commented on 2019-12-06T13:10:56Z

Which controll characters need escaping? 0x00 - 0x1F only? Or are there more of them I'm unaware of?

@LightBender LightBender removed the P3 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants