Skip to content

Commit

Permalink
Fix #170, improve cell attribute error messages (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHatherly authored Aug 14, 2024
1 parent 43f9db9 commit 16e73ac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,19 @@ function extract_cell_options(source::AbstractString; file::AbstractString, line
"""
error(msg)
end
isa(options, Dict) || error("Cell attributes must be a dictionary.")
if !isa(options, Dict)
msg = """
Invalid cell attributes type at $(file):$(line):
```{julia}
$source
```
Expected a dictionary, got $(typeof(options)). Check for
syntax errors in the YAML block at the start of this cell.
"""
error(msg)
end
return options
end
end
Expand Down
13 changes: 12 additions & 1 deletion test/testsets/cell_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ end
line = 1,
)

text = """
```{julia}
#| invalid:true
```
"""
@test_throws_message "file.qmd:1" QuartoNotebookRunner.extract_cell_options(
text;
file = "file.qmd",
line = 1,
)

text = """
```{julia}
a = 1
Expand Down Expand Up @@ -81,7 +92,7 @@ end
server = QuartoNotebookRunner.Server()

buffer = IOBuffer()
@test_throws_message "Cell attributes must be a dictionary." QuartoNotebookRunner.run!(
@test_throws_message "Invalid cell attributes type at" QuartoNotebookRunner.run!(
server,
notebook;
output = buffer,
Expand Down

0 comments on commit 16e73ac

Please sign in to comment.