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

Error messages: allow color from Julia #3046

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -243,11 +244,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 @@ -127,7 +127,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
Loading