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

Improving Printf error messages #45366

Merged
merged 10 commits into from
Jul 8, 2022
Prev Previous commit
Next Next commit
Fix erronous check for IO on @printf argument
Seelengrab committed May 19, 2022
commit ac5f8b2a9e79a4ef2672c6b44794052df9f85d6a
6 changes: 2 additions & 4 deletions stdlib/Printf/src/Printf.jl
Original file line number Diff line number Diff line change
@@ -894,15 +894,13 @@ macro printf(io_or_fmt, args...)
if io_or_fmt isa String
fmt = Format(io_or_fmt)
return esc(:($Printf.format(stdout, $fmt, $(args...))))
elseif io_or_fmt isa IO
else
io = io_or_fmt
isempty(args) && throw(ArgumentError("No format string provided to `@printf` - use like `@printf [io] <format string> [<args...>]."))
fmt_str = first(args)
fmt_str isa String || throw(ArgumentError("First argument after `IO` has to be a format string"))
fmt_str isa String || throw(ArgumentError("First argument after io has to be a format string"))
fmt = Format(fmt_str)
return esc(:($Printf.format($io, $fmt, $(Base.tail(args)...))))
else
throw(ArgumentError("First argument to `@printf` has to be either an `<: IO` to print to or a format `String`."))
end
end