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

handle doi requests for articles with incomplete metadata #13

Closed
AshtonSBradley opened this issue Mar 9, 2023 · 4 comments
Closed

handle doi requests for articles with incomplete metadata #13

AshtonSBradley opened this issue Mar 9, 2023 · 4 comments

Comments

@AshtonSBradley
Copy link

AshtonSBradley commented Mar 9, 2023

If I try something that is new or very old, I hit an error that I guess is needing to handle zero citation data as a special case?

using ShortCodes
DOI("10.1103/PhysRev.65.117")

Failed to show value:

BoundsError: attempt to access 0-element JSON3.Array{Union{}, Vector{UInt8}, Vector{UInt64}} at index [1]

throw_boundserror(::JSON3.Array{Union{}, Vector{UInt8}, Vector{UInt64}}, ::Tuple{Int64})@abstractarray.jl:703
checkbounds@abstractarray.jl:668[inlined]
getindex(::JSON3.Array{Union{}, Vector{UInt8}, Vector{UInt64}}, ::Int64)@JSON3.jl:158
var"##fetch_metadata_unmemoized"(::String)@doi.jl:68
#[email protected]:62[inlined]
get!@iddict.jl:178[inlined]
fetch_metadata@Memoize.jl:61[inlined]
var"##fetch_metadata_unmemoized"(::ShortCodes.DOI{String})@doi.jl:63
#[email protected]:62[inlined]
get!(::ShortCodes.var"#3#4"{ShortCodes.DOI{String}}, ::IdDict{Any, Any}, ::Any)@iddict.jl:178
fetch_metadata(::ShortCodes.DOI{String})@Memoize.jl:61
getproperty(::ShortCodes.DOI{String}, ::Symbol)@doi.jl:26
emph_author(::ShortCodes.DOI{String})@doi.jl:104
show(::IOContext{IOBuffer}, ::MIME{Symbol("text/html")}, ::ShortCodes.DOI{String})@doi.jl:43
show_richest(::IOContext{IOBuffer}, ::Any)@PlutoRunner.jl:1186
show_richest_withreturned@PlutoRunner.jl:1100[inlined]
format_output_default(::Any, ::Any)@PlutoRunner.jl:1000
#format_output#[email protected]:1017[inlined]
#[email protected]:909[inlined]
var"#with_io_to_logs#115"(::Bool, ::Base.CoreLogging.LogLevel, ::typeof(Main.PlutoRunner.with_io_to_logs), ::Main.PlutoRunner.var"#53#56"{Module, ShortCodes.DOI{String}, Dict{Tuple{UInt64, Int64}, Int64}})@PlutoRunner.jl:2424
(::Main.PlutoRunner.var"#119#120"{Bool, Base.CoreLogging.LogLevel, Main.PlutoRunner.var"#53#56"{Module, ShortCodes.DOI{String}, Dict{Tuple{UInt64, Int64}, Int64}}})()@PlutoRunner.jl:2448
with_logstate(::Function, ::Any)@logging.jl:511
with_logger@logging.jl:623[inlined]
#with_logger_and_io_to_logs#[email protected]:2447[inlined]
var"#formatted_result_of#50"(::Bool, ::typeof(Main.PlutoRunner.formatted_result_of), ::Base.UUID, ::Base.UUID, ::Bool, ::Vector{String}, ::Nothing, ::Module)@PlutoRunner.jl:908
top-level scope@WorkspaceManager.jl:527

DOI("10.1103/PhysRevA.107.010101")

Failed to show value:

BoundsError: attempt to access 0-element JSON3.Array{Union{}, Vector{UInt8}, Vector{UInt64}} at index [1]

throw_boundserror(::JSON3.Array{Union{}, Vector{UInt8}, Vector{UInt64}}, ::Tuple{Int64})@abstractarray.jl:703
checkbounds@abstractarray.jl:668[inlined]
getindex(::JSON3.Array{Union{}, Vector{UInt8}, Vector{UInt64}}, ::Int64)@JSON3.jl:158
var"##fetch_metadata_unmemoized"(::String)@doi.jl:68
#[email protected]:62[inlined]
get!@iddict.jl:178[inlined]
fetch_metadata@Memoize.jl:61[inlined]
var"##fetch_metadata_unmemoized"(::ShortCodes.DOI{String})@doi.jl:63
#[email protected]:62[inlined]
get!(::ShortCodes.var"#3#4"{ShortCodes.DOI{String}}, ::IdDict{Any, Any}, ::Any)@iddict.jl:178
fetch_metadata(::ShortCodes.DOI{String})@Memoize.jl:61
getproperty(::ShortCodes.DOI{String}, ::Symbol)@doi.jl:26
emph_author(::ShortCodes.DOI{String})@doi.jl:104
show(::IOContext{IOBuffer}, ::MIME{Symbol("text/html")}, ::ShortCodes.DOI{String})@doi.jl:43
show_richest(::IOContext{IOBuffer}, ::Any)@PlutoRunner.jl:1186
show_richest_withreturned@PlutoRunner.jl:1100[inlined]
format_output_default(::Any, ::Any)@PlutoRunner.jl:1000
#format_output#[email protected]:1017[inlined]
#[email protected]:909[inlined]
var"#with_io_to_logs#115"(::Bool, ::Base.CoreLogging.LogLevel, ::typeof(Main.PlutoRunner.with_io_to_logs), ::Main.PlutoRunner.var"#53#56"{Module, ShortCodes.DOI{String}, Dict{Tuple{UInt64, Int64}, Int64}})@PlutoRunner.jl:2424
(::Main.PlutoRunner.var"#119#120"{Bool, Base.CoreLogging.LogLevel, Main.PlutoRunner.var"#53#56"{Module, ShortCodes.DOI{String}, Dict{Tuple{UInt64, Int64}, Int64}}})()@PlutoRunner.jl:2448
with_logstate(::Function, ::Any)@logging.jl:511
with_logger@logging.jl:623[inlined]
#with_logger_and_io_to_logs#[email protected]:2447[inlined]
var"#formatted_result_of#50"(::Bool, ::typeof(Main.PlutoRunner.formatted_result_of), ::Base.UUID, ::Base.UUID, ::Bool, ::Vector{String}, ::Nothing, ::Module)@PlutoRunner.jl:908
top-level scope@WorkspaceManager.jl:527
@AshtonSBradley AshtonSBradley changed the title handle articles with no citations handle doi requests for articles with no citations Mar 9, 2023
@hellemo
Copy link
Owner

hellemo commented Mar 10, 2023

It's actually missing metadata that leads to this error. This is not new behaviour on ShortCodes' part, but apparently the new API has less coverage in terms of dois, so I agree it's quite annoying.

I originally figured there was no use in a fallback method for missing metadata, but willing to reconsider if there are good suggestions for what the fallback behavior should be. Just displaying the doi, perhaps?

julia> using Revise, ShortCodes

julia> ShortCodes.fetch_citation_count("10.1103/PhysRev.65.117")
4661

julia> ShortCodes.fetch_metadata("10.1103/PhysRev.65.117")
ERROR: BoundsError: attempt to access 0-element JSON3.Array{Union{}, Vector{UInt8}, Vector{UInt64}} at index [1]
Stacktrace:
 [1] throw_boundserror(A::JSON3.Array{Union{}, Vector{UInt8}, Vector{UInt64}}, I::Tuple{Int64})
   @ Base ./abstractarray.jl:745
 [2] checkbounds
   @ ./abstractarray.jl:710 [inlined]
 [3] getindex(arr::JSON3.Array{Union{}, Vector{UInt8}, Vector{UInt64}}, i::Int64)
   @ JSON3 ~/.julia/packages/JSON3/CpNms/src/JSON3.jl:158
 [4] var"##fetch_metadata_unmemoized"(doi::String)
   @ ShortCodes ~/code/ShortCodes.jl/src/doi.jl:68
 [5] #5
   @ ~/.julia/packages/Memoize/12ANR/src/Memoize.jl:62 [inlined]
 [6] get!
   @ ./iddict.jl:178 [inlined]
 [7] fetch_metadata(doi::String)
   @ ShortCodes ~/.julia/packages/Memoize/12ANR/src/Memoize.jl:61
 [8] top-level scope
   @ REPL[4]:1
julia>

@AshtonSBradley
Copy link
Author

AshtonSBradley commented Mar 10, 2023

It's actually missing metadata that leads to this error. This is not new behaviour on ShortCodes' part, but apparently the new API has less coverage in terms of dois, so I agree it's quite annoying.

I originally figured there was no use in a fallback method for missing metadata, but willing to reconsider if there are good suggestions for what the fallback behavior should be. Just displaying the doi, perhaps?

julia> using Revise, ShortCodes

julia> ShortCodes.fetch_citation_count("10.1103/PhysRev.65.117")
4661

julia> ShortCodes.fetch_metadata("10.1103/PhysRev.65.117")
ERROR: BoundsError: attempt to access 0-element JSON3.Array{Union{}, Vector{UInt8}, Vector{UInt64}} at index [1]
Stacktrace:
 [1] throw_boundserror(A::JSON3.Array{Union{}, Vector{UInt8}, Vector{UInt64}}, I::Tuple{Int64})
   @ Base ./abstractarray.jl:745
 [2] checkbounds
   @ ./abstractarray.jl:710 [inlined]
 [3] getindex(arr::JSON3.Array{Union{}, Vector{UInt8}, Vector{UInt64}}, i::Int64)
   @ JSON3 ~/.julia/packages/JSON3/CpNms/src/JSON3.jl:158
 [4] var"##fetch_metadata_unmemoized"(doi::String)
   @ ShortCodes ~/code/ShortCodes.jl/src/doi.jl:68
 [5] #5
   @ ~/.julia/packages/Memoize/12ANR/src/Memoize.jl:62 [inlined]
 [6] get!
   @ ./iddict.jl:178 [inlined]
 [7] fetch_metadata(doi::String)
   @ ShortCodes ~/.julia/packages/Memoize/12ANR/src/Memoize.jl:61
 [8] top-level scope
   @ REPL[4]:1
julia>

I agree, if missing metadata, a good fallback would be just to show the doi link.

@AshtonSBradley
Copy link
Author

I'm happy to have a go at this if you can suggest the right place to set the fallback from the metadata error

@AshtonSBradley AshtonSBradley changed the title handle doi requests for articles with no citations handle doi requests for articles with incomplete metadata Mar 17, 2023
@stefanbringuier
Copy link
Contributor

@AshtonSBradley I created a pull request (#14) that hopefully fixes this. I didn't touch the Base.show methods so the displayed result may have preceding or trailing white space after the doi link.

@hellemo hellemo closed this as completed in 489fe53 Oct 1, 2023
hellemo added a commit that referenced this issue Oct 1, 2023
Fallback support for failed metadata retrieval (Fixes #13).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants