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

Add error hints for package extensions #184

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

ph-kev
Copy link
Member

@ph-kev ph-kev commented Dec 5, 2024

closes #15 - This PR adds error hints for functions in the package extensions.

For example, if you run this

import ClimaAnalysis.Visualize as viz
import ClimaAnalysis
import Makie
using OrderedCollections
long = 0.0:180.0 |> collect
lat = 0.0:90.0 |> collect
data2D = reshape(1.0:(91 * 181), (181, 91))
dims2D = OrderedDict(["lon" => long, "lat" => lat])
attribs = Dict([
    "short_name" => "name",
    "units" => "units"
])
dim_attributes2D = OrderedDict([
    "lon" => Dict(["units" => "degrees"]),
    "lat" => Dict(["units" => "degrees"]),
])
var2D = ClimaAnalysis.OutputVar(attribs, dims2D, dim_attributes2D, data2D)
fig = Makie.Figure()

viz.heatmap2D_on_globe!(fig, var2D)

Then, you get the error

ERROR: MethodError: no method matching heatmap2D_on_globe!(::Makie.Figure, ::ClimaAnalysis.Var.OutputVar{Vector{…}, Base.ReshapedArray{…}, String, Dict{…}})
The function `heatmap2D_on_globe!` exists, but no method is defined for this combination of argument types.
Import GeoMakie to enable `heatmap2D_on_globe!`. You might also need to import Makie and its backends (CairoMakie, GLMake, etc.) as well.

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 98.19%. Comparing base (e4494a8) to head (5154e23).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/Visualize.jl 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #184      +/-   ##
==========================================
- Coverage   98.35%   98.19%   -0.16%     
==========================================
  Files          11       12       +1     
  Lines        1215     1220       +5     
==========================================
+ Hits         1195     1198       +3     
- Misses         20       22       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ph-kev ph-kev requested a review from Sbozzolo December 6, 2024 00:13
src/Visualize.jl Outdated
if Symbol(exc.f) in fns && !is_pkg_loaded(pkg)
print(
io,
"\nImport $pkg to enable `$(exc.f)`. You might also need to import Makie and its backends (CairoMakie, GLMake, etc.) as well.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should split and return the precise package that needs to be leaded (ie, a Makie backend or GeoMakie)

Also, I don't know if it helps but there's a Base.get_extension function that directly checks if the extension has been loaded. I am not sure if there's any advantage with respect to using is_pkg_loaded

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible to use Base.get_extension instead of is_pkg_loaded. For this particular case, it doesn't matter since you just need to load in one package to enable the extension. However, if an extension requires multiple packages to be loaded, then just checking the extension means you don't know what packages are loaded or are not loaded.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thank you!

@ph-kev ph-kev force-pushed the kp/register-error-hints branch from 3956c15 to 5154e23 Compare December 9, 2024 19:42
@Sbozzolo Sbozzolo self-requested a review December 9, 2024 20:19
@Sbozzolo
Copy link
Member

Sbozzolo commented Dec 9, 2024

Thank you!

@ph-kev ph-kev merged commit 09e360d into CliMA:main Dec 10, 2024
7 of 9 checks passed
@Sbozzolo Sbozzolo mentioned this pull request Dec 11, 2024
1 task
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

Successfully merging this pull request may close these issues.

register error hints?
2 participants