Bug 15348 – std.stdio.writef format specifier error message
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-11-16T23:25:33Z
Last change time
2021-03-22T02:41:27Z
Keywords
pull
Assigned to
No Owner
Creator
ricky maicle
Comments
Comment #0 by rmaicle — 2015-11-16T23:25:33Z
The code below throws a FormatException but reports an error from the library source instead of reporting the error from the offending line in the user program. Also, a more informative error message would help.
import std.stdio;
void main()
{
writef("%*10d", 100);
}
std.format.FormatException@std/format.d(978): $ expected
----------------
??:? pure @safe bool std.exception.enforceEx!(std.format.FormatException).enforceEx!(bool).enforceEx(bool, lazy immutable(char)[], immutable(char)[], ulong) [0x43773e]
??:? pure @safe void std.format.FormatSpec!(char).FormatSpec.fillUp() [0x447503]
??:? @safe bool std.format.FormatSpec!(char).FormatSpec.writeUpToNextSpec!(std.stdio.File.LockingTextWriter).writeUpToNextSpec(std.stdio.File.LockingTextWriter) [0x43812b]
??:? @safe uint std.format.formattedWrite!(std.stdio.File.LockingTextWriter, char, int).formattedWrite(std.stdio.File.LockingTextWriter, const(char[]), int) [0x436f51]
??:? @safe void std.stdio.File.writef!(char, int).writef(const(char[]), int) [0x436e87]
??:? @safe void std.stdio.writef!(immutable(char)[], int).writef(immutable(char)[], int) [0x436deb]
??:? _Dmain [0x436d9f]
??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [0x443c7a]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x443bd0]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [0x443c36]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x443bd0]
??:? _d_run_main [0x443b2d]
??:? main [0x43f88d]
??:? __libc_start_main [0x7a34460f]
===============
Additional Info
DMD64 D Compiler v2.069
Linux sphere-0 4.1.12-1-MANJARO #1 SMP PREEMPT Tue Oct 27 22:11:47 UTC 2015 x86_64 GNU/Linux
Comment #1 by nick — 2018-04-21T12:46:10Z
Just for reference, you can now use a compile-time format string - you get an error for the right source line (after the first error):
writef!"%*10d"(100);
/dlang/dmd/src/phobos/std/stdio.d(3878): Error: static assert: "$ expected"
onlineapp.d(5): instantiated from here: writef!("%*10d", int)
Fixing this issue could still be useful for runtime format strings.
Comment #2 by bugzilla — 2019-12-20T14:18:03Z
(In reply to ric from comment #0)
> The code below throws a FormatException but reports an error from the
> library source instead of reporting the error from the offending line in the
> user program.
That's not true. The last line contains the error in the user program. When compiling with -g you would see there:
[...]
test.d:5 _Dmain [0x47437c1]
> Also, a more informative error message would help.
Yeah, something like "$ expected while parsing the format string" maybe?
Comment #3 by dlang-bot — 2021-03-21T20:21:50Z
@berni44 created dlang/phobos pull request #7899 "Fix Issue 15348 - std.stdio.writef format specifier error message" fixing this issue:
- Fix Issue 15348 - std.stdio.writef format specifier error message
https://github.com/dlang/phobos/pull/7899
Comment #4 by dlang-bot — 2021-03-22T02:41:27Z
dlang/phobos pull request #7899 "Fix Issue 15348 - std.stdio.writef format specifier error message" was merged into master:
- bb64a4233a97bbed6f9b9a32fa2ef41df4c398f3 by berni44:
Fix Issue 15348 - std.stdio.writef format specifier error message
https://github.com/dlang/phobos/pull/7899