D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15348 - std.stdio.writef format specifier error message
Summary: std.stdio.writef format specifier error message
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 minor
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2015-11-16 23:25 UTC by ricky maicle
Modified: 2021-03-22 02:41 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ricky maicle 2015-11-16 23:25:33 UTC
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 Nick Treleaven 2018-04-21 12:46:10 UTC
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 berni44 2019-12-20 14:18:03 UTC
(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 Dlang Bot 2021-03-21 20:21:50 UTC
@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 Dlang Bot 2021-03-22 02:41:27 UTC
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