Skip to content

Commit

Permalink
Error message title
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Oct 3, 2024
1 parent 5637bfc commit 78eb454
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
34 changes: 27 additions & 7 deletions frontend/components/ErrorMessage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cl } from "../common/ClassTable.js"
import { PlutoActionsContext } from "../common/PlutoContext.js"
import { html, useContext, useEffect, useLayoutEffect, useRef, useState } from "../imports/Preact.js"
import { html, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "../imports/Preact.js"
import { highlight } from "./CellOutput.js"
import { PkgTerminalView } from "./PkgTerminalView.js"
import _ from "../imports/lodash.js"
Expand Down Expand Up @@ -205,10 +205,7 @@ export const ParseError = ({ cell_id, diagnostics }) => {
>
<div class="classical-frame">
${message}
<div class="frame-source">
${at}
<${StackFrameFilename} frame=${{ file: "#==#" + cell_id, line }} cell_id=${cell_id} />
</div>
<div class="frame-source">${at}<${StackFrameFilename} frame=${{ file: "#==#" + cell_id, line }} cell_id=${cell_id} /></div>
</div>
</li>`
)}
Expand All @@ -227,6 +224,11 @@ const frame_is_important_heuristic = (frame, frame_index, limited_stacktrace, fr
return false
}

if (funcname.includes("throw")) return false

// too sciency
if (frame.inlined) return false

if (params == null) {
// no type signature... must be some function call that got optimized away or something special
// probably not directly relevant
Expand Down Expand Up @@ -422,7 +424,14 @@ export const ErrorMessage = ({ msg, stacktrace, cell_id }) => {
(frame) => !(ignore_location(frame) && ignore_funccall(frame))
)

const first_package = get_first_package(limited_stacktrace)

return html`<jlerror>
<div class="error-header">
<secret-h1>Error message${first_package == null ? null : ` from ${first_package}`}</secret-h1>
<!-- <p>This message was included with the error:</p> -->
</div>
<header>${matched_rewriter.display(msg)}</header>
${stacktrace.length == 0 || !(matched_rewriter.show_stacktrace?.() ?? true)
? null
Expand All @@ -443,8 +452,7 @@ export const ErrorMessage = ({ msg, stacktrace, cell_id }) => {
<div class="classical-frame">
<${Funccall} frame=${frame} />
<div class="frame-source">
${at}
<${StackFrameFilename} frame=${frame} cell_id=${cell_id} />
${at}<${StackFrameFilename} frame=${frame} cell_id=${cell_id} />
<${DocLink} frame=${frame} />
</div>
</div>
Expand All @@ -468,6 +476,18 @@ export const ErrorMessage = ({ msg, stacktrace, cell_id }) => {
</jlerror>`
}

const get_first_package = (limited_stacktrace) => {
for (let [i, frame] of limited_stacktrace.entries()) {
const frame_cell_id = extract_cell_id(frame.file)
if (frame_cell_id) return undefined

const important = frame_is_important_heuristic(frame, i, limited_stacktrace, frame_cell_id)
if (!important) continue

if (frame.source_package) return frame.source_package
}
}

const get_erred_upstreams = (
/** @type {import("./Editor.js").NotebookData?} */ notebook,
/** @type {string} */ cell_id,
Expand Down
4 changes: 4 additions & 0 deletions frontend/treeview.css
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ jlerror > section > ol > li {
jlerror > section > ol > li:not(.important):not(:hover) {
opacity: 0.5;
}

jlerror > section > ol > li:not(.important)::marker {
font-weight: 100;
}
jlerror > section > ol > li.from_this_notebook {
--bg: var(--jl-info-acccolor);
background: var(--bg);
Expand Down

0 comments on commit 78eb454

Please sign in to comment.