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

Unclear error message with misspecified arguments to at-printf #18096

Closed
johnmyleswhite opened this issue Aug 17, 2016 · 2 comments
Closed

Unclear error message with misspecified arguments to at-printf #18096

johnmyleswhite opened this issue Aug 17, 2016 · 2 comments
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. domain:error handling Handling of exceptions by Julia or the user stdlib Julia's standard library

Comments

@johnmyleswhite
Copy link
Member

Perhaps not worth trying to improve, but the error message I get when misusing @printf in the following way is not very clear:

julia> i = 1
1

julia> buffer = [0.0]
1-element Array{Float64,1}:
 0.0

julia> output = [0.0]
1-element Array{Float64,1}:
 0.0

julia> @printf("%d\t%f\t%s\n", i, buffer, output[i])
1   ERROR: TypeError: non-boolean (Array{Bool,1}) used in boolean context

Worth trying to improve?

@quinnj
Copy link
Member

quinnj commented Sep 8, 2020

The big question here is whether we want to do argument checking for things passed to @printf. Even with the code recently overhauled, we still don't restrictions on arguments passed; partly this allows easy integration for custom types that want to "hook into" the Printf machinery. I'm not sure there's a super clean way to check that each argument is a "scalar" either, which is probably roughly what we'd want here.

@vtjnash vtjnash added domain:display and printing Aesthetics and correctness of printed representations of objects. stdlib Julia's standard library labels Jan 31, 2024
@vtjnash
Copy link
Sponsor Member

vtjnash commented Jan 31, 2024

seems okay to me now:

julia> @printf("%d\t%f\t%s\n", i, buffer, output[i])
ERROR: MethodError: no method matching Float64(::Vector{Float64})

Closest candidates are:
  Float64(!Matched::Int128)
   @ Base float.jl:262
  Float64(!Matched::Bool)
   @ Base float.jl:227
  Float64(!Matched::Int16)
   @ Base float.jl:221
  ...

Stacktrace:
 [1] tofloat(x::Vector{Float64})
   @ Printf ~/julia/usr/share/julia/stdlib/v1.11/Printf/src/Printf.jl:486
 [2] fmt(buf::Vector{UInt8}, pos::Int64, arg::Vector{Float64}, spec::Printf.Spec{Val{'f'}})
   @ Printf ~/julia/usr/share/julia/stdlib/v1.11/Printf/src/Printf.jl:503
 [3] fmt
   @ ~/julia/usr/share/julia/stdlib/v1.11/Printf/src/Printf.jl:315 [inlined]
 [4] format(::Vector{UInt8}, ::Int64, ::Printf.Format{Base.CodeUnits{…}, Tuple{…}}, ::Int64, ::Vararg{Any})
   @ Printf ~/julia/usr/share/julia/stdlib/v1.11/Printf/src/Printf.jl:836
 [5] format(::Base.TTY, ::Printf.Format{Base.CodeUnits{…}, Tuple{…}}, ::Int64, ::Vector{Float64}, ::Vararg{Any})
   @ Printf ~/julia/usr/share/julia/stdlib/v1.11/Printf/src/Printf.jl:937
 [6] top-level scope
   @ REPL[9]:1
Some type information was truncated. Use `show(err)` to see complete types.

@vtjnash vtjnash closed this as completed Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. domain:error handling Handling of exceptions by Julia or the user stdlib Julia's standard library
Projects
None yet
Development

No branches or pull requests

4 participants