Skip to content

Commit 83a676b

Browse files
committed
Improve error message for undownloadable artifacts
This commit adds a message to the already existing error message that the artifact may be undownloadable and suggests to manually download the artifact and adds the artifact to Overrides.toml if this is the case.
1 parent 1d114d3 commit 83a676b

File tree

2 files changed

+74
-31
lines changed

2 files changed

+74
-31
lines changed

NEWS.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,13 @@ The default cache size for regridded fields in `DataHandler` was reduced from
7373
128 to 2, reducing the memory footprint. You can pass the `cache_max_size`
7474
keyword argument to control this value.
7575

76-
#### Error hints
76+
#### Improved error handling
7777

78-
When using a function that depends on loading another package, the error now tells the user
79-
which package should be loaded if the package has not been loaded already.
78+
When using a function that depends on loading another package, the error now
79+
tells the user which package should be loaded if the package has not been loaded
80+
already. Furthermore, if there is an error with `@clima_artifact`, the error
81+
message tells the user that the artifact might be undownloadable and recommends
82+
downloading it themselves.
8083

8184
v0.1.19
8285
------

src/ClimaArtifacts.jl

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,31 @@ macro clima_artifact(name, context = nothing)
124124
# processes have the artifact string
125125
if isnothing($(esc(context))) ||
126126
Base.invokelatest(iamroot, $(esc(context)))
127-
artifact_path = Base.invokelatest(
127+
try
128+
artifact_path = Base.invokelatest(
129+
JuliaArtifacts._artifact_str,
130+
$(__module__),
131+
$(artifacts_toml),
132+
$(artifact_name),
133+
$(artifact_path_tail),
134+
$(artifact_dict),
135+
$(hash),
136+
$(platform),
137+
LazyArtifacts,
138+
)::String
139+
catch e
140+
if e isa ErrorException
141+
msg = "\nThe artifact may also be too large to be downloaded automatically. If this is the case, download the artifact directly and indicate where the artifact lives in Overrides.toml (see ClimaArtifacts documentation for how to do this)."
142+
new_err = ErrorException(e.msg * msg)
143+
rethrow(new_err)
144+
else
145+
rethrow(e)
146+
end
147+
end
148+
end
149+
push!(ACCESSED_ARTIFACTS, artifact_name)
150+
try
151+
Base.invokelatest(
128152
JuliaArtifacts._artifact_str,
129153
$(__module__),
130154
$(artifacts_toml),
@@ -135,19 +159,15 @@ macro clima_artifact(name, context = nothing)
135159
$(platform),
136160
LazyArtifacts,
137161
)::String
162+
catch e
163+
if e isa ErrorException
164+
msg = "\nThe artifact may also be too large to be downloaded automatically. If this is the case, download the artifact directly and indicate where the artifact lives in Overrides.toml (see ClimaArtifacts documentation for how to do this)."
165+
new_err = ErrorException(e.msg * msg)
166+
rethrow(new_err)
167+
else
168+
rethrow(e)
169+
end
138170
end
139-
push!(ACCESSED_ARTIFACTS, artifact_name)
140-
Base.invokelatest(
141-
JuliaArtifacts._artifact_str,
142-
$(__module__),
143-
$(artifacts_toml),
144-
$(artifact_name),
145-
$(artifact_path_tail),
146-
$(artifact_dict),
147-
$(hash),
148-
$(platform),
149-
LazyArtifacts,
150-
)::String
151171
end
152172
else
153173
# If artifact_name is not a string (e.g., it is a variable), we have to do all the
@@ -184,7 +204,33 @@ macro clima_artifact(name, context = nothing)
184204
# processes have the artifact string
185205
if isnothing($(esc(context))) ||
186206
Base.invokelatest(iamroot, $(esc(context)))
187-
artifact_path = Base.invokelatest(
207+
try
208+
artifact_path = Base.invokelatest(
209+
JuliaArtifacts._artifact_str,
210+
$(__module__),
211+
$(artifacts_toml),
212+
artifact_name,
213+
artifact_path_tail,
214+
$(artifact_dict),
215+
hash,
216+
platform,
217+
LazyArtifacts,
218+
)::String
219+
catch e
220+
if e isa ErrorException
221+
msg = "\nThe artifact may also be too large to be downloaded automatically. If this is the case, download the artifact directly and indicate where the artifact lives in Overrides.toml (see ClimaArtifacts documentation for how to do this)."
222+
new_err = ErrorException(e.msg * msg)
223+
rethrow(new_err)
224+
else
225+
rethrow(e)
226+
end
227+
end
228+
end
229+
push!(ACCESSED_ARTIFACTS, artifact_name)
230+
isnothing($(esc(context))) ||
231+
Base.invokelatest(barrier, $(esc(context)))
232+
try
233+
Base.invokelatest(
188234
JuliaArtifacts._artifact_str,
189235
$(__module__),
190236
$(artifacts_toml),
@@ -195,21 +241,15 @@ macro clima_artifact(name, context = nothing)
195241
platform,
196242
LazyArtifacts,
197243
)::String
244+
catch e
245+
if e isa ErrorException
246+
msg = "\nThe artifact may also be too large to be downloaded automatically. If this is the case, download the artifact directly and indicate where the artifact lives in Overrides.toml (see ClimaArtifacts documentation for how to do this)."
247+
new_err = ErrorException(e.msg * msg)
248+
rethrow(new_err)
249+
else
250+
rethrow(e)
251+
end
198252
end
199-
push!(ACCESSED_ARTIFACTS, artifact_name)
200-
isnothing($(esc(context))) ||
201-
Base.invokelatest(barrier, $(esc(context)))
202-
Base.invokelatest(
203-
JuliaArtifacts._artifact_str,
204-
$(__module__),
205-
$(artifacts_toml),
206-
artifact_name,
207-
artifact_path_tail,
208-
$(artifact_dict),
209-
hash,
210-
platform,
211-
LazyArtifacts,
212-
)::String
213253
end
214254
end
215255
end

0 commit comments

Comments
 (0)