Skip to content

Commit 323094f

Browse files
committed
throw error in trixi_include when assignment is not found
1 parent a7dcc23 commit 323094f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/util.jl

+16
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ julia> redirect_stdout(devnull) do
9696
```
9797
"""
9898
function trixi_include(mod::Module, example::AbstractString; kwargs...)
99+
# Check that all kwargs exist as assignments
100+
code = read(example, String)
101+
expr = Meta.parse("begin \n$code \nend")
102+
expr = insert_maxiters(expr)
103+
104+
for (key, val) in kwargs
105+
# This will throw an error when `key` is not found
106+
find_assignment(expr, key)
107+
end
108+
99109
Base.include(ex -> replace_assignments(insert_maxiters(ex); kwargs...), mod, example)
100110
end
101111

@@ -282,19 +292,25 @@ end
282292
function find_assignment(expr, destination)
283293
# declare result to be able to assign to it in the closure
284294
local result
295+
found = false
285296

286297
# find explicit and keyword assignments
287298
walkexpr(expr) do x
288299
if x isa Expr
289300
if (x.head === Symbol("=") || x.head === :kw) &&
290301
x.args[1] === Symbol(destination)
291302
result = x.args[2]
303+
found = true
292304
# dump(x)
293305
end
294306
end
295307
return x
296308
end
297309

310+
if !found
311+
throw(ArgumentError("assignment `$destination` not found in expression"))
312+
end
313+
298314
result
299315
end
300316

0 commit comments

Comments
 (0)