Skip to content

Commit

Permalink
Error messages: allow color from Julia (#3046)
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp authored Oct 4, 2024
1 parent 4190ad0 commit 08615ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion frontend/components/ErrorMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { highlight } from "./CellOutput.js"
import { PkgTerminalView } from "./PkgTerminalView.js"
import _ from "../imports/lodash.js"
import { open_bottom_right_panel } from "./BottomRightPanel.js"
import AnsiUp from "../imports/AnsiUp.js"

const extract_cell_id = (/** @type {string} */ file) => {
const sep_index = file.indexOf("#==#")
Expand Down Expand Up @@ -279,11 +280,22 @@ const frame_is_important_heuristic = (frame, frame_index, limited_stacktrace, fr
return true
}

const AnsiUpLine = (/** @type {{value: string}} */ { value }) => {
const node_ref = useRef(/** @type {HTMLElement?} */ (null))

useEffect(() => {
if (!node_ref.current) return
node_ref.current.innerHTML = new AnsiUp().ansi_to_html(value)
}, [node_ref.current, value])

return value === "" ? html`<p><br /></p>` : html`<p ref=${node_ref}></p>`
}

export const ErrorMessage = ({ msg, stacktrace, cell_id }) => {
let pluto_actions = useContext(PlutoActionsContext)
const default_rewriter = {
pattern: /.?/,
display: (/** @type{string} */ x) => _.dropRightWhile(x.split("\n"), (s) => s === "").map((line) => html`<p>${line === "" ? html`<br />` : line}</p>`),
display: (/** @type{string} */ x) => _.dropRightWhile(x.split("\n"), (s) => s === "").map((line) => html`<${AnsiUpLine} value=${line} />`),
}
const rewriters = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/runner/PlutoRunner/src/display/Exception.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ end
"Because even showerror can error... 👀"
function try_showerror(io::IO, e, args...)
try
showerror(io, e, args...)
showerror(IOContext(io, :color => true), e, args...)
catch show_ex
print(io, "\nFailed to show error:\n\n")
try_showerror(io, show_ex, stacktrace(catch_backtrace()))
Expand Down

0 comments on commit 08615ff

Please sign in to comment.