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

Improve error message when running TestEnv.activate() twice #35

Open
nickrobinson251 opened this issue Nov 26, 2021 · 2 comments · Fixed by #79
Open

Improve error message when running TestEnv.activate() twice #35

nickrobinson251 opened this issue Nov 26, 2021 · 2 comments · Fixed by #79
Labels
enhancement New feature or request

Comments

@nickrobinson251
Copy link
Contributor

in v1.6:

julia> TestEnv.activate()
┌ Warning: Could not use exact versions of packages in manifest, re-resolving
└ @ TestEnv ~/.julia/packages/TestEnv/0IT5L/src/activate_set.jl:60
"/var/folders/hx/1h0bbkfd18d4n1qrnwmrl4j00000gn/T/jl_HNWFMu/Project.toml"

julia> TestEnv.activate()
ERROR: type Nothing has no field name
Stacktrace:
 [1] getproperty(x::Nothing, f::Symbol)
   @ Base ./Base.jl:33
 [2] current_pkg_name
   @ ~/.julia/packages/TestEnv/0IT5L/src/common.jl:10 [inlined]
 [3] activate()
   @ TestEnv ~/.julia/packages/TestEnv/0IT5L/src/activate_set.jl:7
 [4] top-level scope
   @ REPL[1]:1

I accidentally ran TestEnv twice, i.e. ran TestEnv in a "test env", and didn't realise that's what i'd done, saw a scary error and paniced unneccarily (clearly i spook easily)

I think ideally this error or warn with something a little more informative

e.g. change (for the 1.4-1.6 code)

current_pkg_name() = Context().env.pkg.name

to something like

function current_pkg_name()
    env = Context().env
    pkg = env.pkg
    pkg == nothing && error("Not in a named project with test dependencies: $(env.project_file)")
    return pkg.name 
end    

i've not tested/looked into other julia versions.

@oxinabox oxinabox added the enhancement New feature or request label Nov 30, 2021
@oxinabox
Copy link
Member

Sounds good.
A PR would be appreciated.
(Make a PR to one branch and I will cherry pick it for the others)

@IanButterworth
Copy link

This also happens if you forget to activate a package and do it in the @x.x env

julia> using TestEnv

julia> TestEnv.activate()
ERROR: type Nothing has no field name
Stacktrace:
 [1] getproperty(x::Nothing, f::Symbol)
   @ Base ./Base.jl:33
 [2] current_pkg_name
   @ ~/.julia/packages/TestEnv/0IT5L/src/common.jl:10 [inlined]
 [3] activate()
   @ TestEnv ~/.julia/packages/TestEnv/0IT5L/src/activate_set.jl:7
 [4] top-level scope
   @ REPL[2]:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants