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

InexactError shows Inf16 as Inf #51087

Closed
LilithHafner opened this issue Aug 28, 2023 · 8 comments · Fixed by #52491
Closed

InexactError shows Inf16 as Inf #51087

LilithHafner opened this issue Aug 28, 2023 · 8 comments · Fixed by #52491
Labels
error messages Better, more actionable error messages good first issue Indicates a good issue for first-time contributors to Julia

Comments

@LilithHafner
Copy link
Member

This is slightly misleading:

julia> UInt128(Inf16)
ERROR: InexactError: UInt128(Inf)
Stacktrace:
 [1] UInt128(x::Float16)
   @ Base ./float.jl:888
 [2] top-level scope
   @ REPL[1]:1

The 16 is lost is here:
https://github.com/JuliaLang/julia/blob/b4052a5fa5af2c006612c962d6cf26808575c01b/base/errorshow.jl#L177C5-L177C27

@LilithHafner LilithHafner added good first issue Indicates a good issue for first-time contributors to Julia error messages Better, more actionable error messages labels Aug 28, 2023
@Jay-sanjay
Copy link
Contributor

Hello , sir I will like to help for this issue , will you please provide with some hints for how to resolve this error message

@LilithHafner
Copy link
Member Author

Thanks!

I think the error is in the function

function showerror(io::IO, ex::InexactError)
    print(io, "InexactError: ", ex.func, '(')
    nameof(ex.T) === ex.func || print(io, ex.T, ", ")
    print(io, ex.val, ')')
    Experimental.show_error_hints(io, ex)
end

defined in base/errorshow.jl

So if you can find a different implementation of the function that shows Inf16 as Inf16, that would fix it.

You could try redefining the function in a repl with

julia> function Base.showerror(io::IO, ex::InexactError)
    print(io, "something new")
end

julia> UInt128(Inf16)
ERROR: something new
[...]

to get it to preserve the type information. I suspect calling a different show method (e.g. show instead of print) might work.

@Jay-sanjay
Copy link
Contributor

Thank you sir !
Yes I will start on it .

@longemen3000
Copy link
Contributor

longemen3000 commented Sep 2, 2023

you could replace print(io, ex.val, ')') for print(io, repr(ex.val), ')'), that should fix the error, as:

julia> repr(Inf16)
"Inf16"

@Jay-sanjay
Copy link
Contributor

@LilithHafner @longemen3000 Sir I guess the code provided above got changed a bit , so what next can be done

join(io, ex.args[2:end], ", ")

@ghost
Copy link

ghost commented Nov 18, 2023

Hi, if this is still open, I can attempt it too

Edit: Ah, nvm, looks like it's been resolved (am new to open-source)

@LilithHafner
Copy link
Member Author

This has not yet been resolved. In general, we try to mark all resolved issues as closed and all unresolved issues as open.

@Pietro-D
Copy link

I think i have a solution. I opened a PR #52317

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error messages Better, more actionable error messages good first issue Indicates a good issue for first-time contributors to Julia
Projects
None yet
4 participants