2016-11-27 100 views
1

指這一段:Pkg.installed(「anInvalidPackage」)應該什麼都不返回或拋出錯誤?

installed(pkg) → Void | VersionNumber

If pkg is installed, return the installed version number, otherwise return nothing. 

JuliaDoc

Pkg.installed("anInvalidPackage")函數返回nothing但它拋出一個錯誤:

julia> VERSION 
v"0.5.0" 
julia> Pkg.installed("anInvalidPackage") 
ERROR: anInvalidPackage is not a package (not registered or installed) 
in installed(::String) at .\pkg\entry.jl:123 
in (::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#installed,Tuple{String}}) 
() at .\pkg\dir.jl:31 
in cd(::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#installed,Tuple{String} 
}, ::String) at .\file.jl:48 
in #cd#1 at .\pkg\dir.jl:31 
in installed(::String) at .\pkg\pkg.jl:129 

編輯issue

+0

奇怪,怎麼去掉 「的」 從字符串... 「 – daycaster

+0

@daycaster錯字 –

+0

」那麼,沃森,這是消除了這一線的調查!「 :) – daycaster

回答

2

如果我們的故事一看T IN基地PKG模塊的源代碼,它應該給使用一些線索:

function installed(pkg::AbstractString) 
    avail = Read.available(pkg) 
    if Read.isinstalled(pkg) 
     res = typemin(VersionNumber) 
     ### some libgit2 stuff ### 
    end 
    isempty(avail) && throw(PkgError("$pkg is not a package (not registered or installed)")) 
    return nothing # registered but not installed 
end 

從最後兩行,我們可以看到,朱莉婭是要拋出一個錯誤,如果包是未註冊或安裝。但是,如果包裝註冊了但未安裝,則不會拋出錯誤並返回nothing

所以

var = Pkg.installed("AMD") # returns nothing for me as I don't have AMD installed 
          # but it is a registered package 

但是:

altvar = Pkg.installed("this_is_not_the_name_of_any_package") 
# will throw an error 

我同意文檔或許應該使這更清楚......

相關問題