D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 755 - std.utf.decode() throws exception with unclear error message
Summary: std.utf.decode() throws exception with unclear error message
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P3 trivial
Assignee: Andrei Alexandrescu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-27 11:31 UTC by Luís Marques
Modified: 2014-02-15 13:26 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Luís Marques 2006-12-27 11:31:58 UTC
On line 345 of utf.d (std.utf) we can find:

throw new UtfException("4invalid UTF-8 sequence", i);

The "4" seems to be a typo (which makes for ugly error messages:)
Comment 1 Matti Niemenmaa 2006-12-28 06:42:51 UTC
It's not a typo: within std.utf you'll find "Ninvalid UTF-8 sequence", where N ranges from 1 to 5. 4 is just the most common, because it's in the decode() method which is used by std.format.doFormat, which, in turn, is used by the writef family.

I agree, however, that it makes for ugly error messages, and it does appear a lot like a typo, so I'll leave the bug open - just renamed.
Comment 2 Luís Marques 2006-12-28 07:51:49 UTC
Ok, changing the message seems a fine choice to me.
Perhaps "invalid UTF-8 sequence at byte X"?
Comment 3 Andrei Alexandrescu 2010-09-13 20:32:44 UTC
I replaced the culprit with:

    throw new UtfException(text("dchar decode(in char[], ref size_t): "
                    "Invalid UTF-8 sequence ", cast(const ubyte[]) s,
                    " around index ", i));

http://www.dsource.org/projects/phobos/changeset/1999