Bug 755 – std.utf.decode() throws exception with unclear error message

Status
RESOLVED
Resolution
FIXED
Severity
trivial
Priority
P3
Component
phobos
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2006-12-27T11:31:00Z
Last change time
2014-02-15T13:26:32Z
Assigned to
andrei
Creator
luis

Comments

Comment #0 by luis — 2006-12-27T11:31:58Z
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 by matti.niemenmaa+dbugzilla — 2006-12-28T06:42:51Z
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 by luis — 2006-12-28T07:51:49Z
Ok, changing the message seems a fine choice to me. Perhaps "invalid UTF-8 sequence at byte X"?
Comment #3 by andrei — 2010-09-13T20:32:44Z
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