Skip to content

JS-error improvements #7818

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

Merged
merged 3 commits into from
May 31, 2025
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
3 changes: 3 additions & 0 deletions app/css/bootcamp/components/editor-information-tooltip.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
&.error {
@apply bg-white border-2 border-red-500;

@apply p-0;

filter: drop-shadow(0px 4px 8px rgba(79, 114, 205, 0.5));

h2 {
Expand All @@ -89,6 +91,7 @@
}
}
.content {
@apply rounded-6;
@apply text-textColor1;
@apply pt-10 px-20 pb-12;
@apply relative z-tooltip-content bg-white;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ import { marked } from 'marked'
import type { StaticError } from '@/interpreter/error'
import { SyntaxError } from '@/interpreter/error'

export function describeError(error: StaticError, context?: string) {
export function describeError(
error: StaticError,
language: 'jikiscript' | 'javascript',
context?: string
) {
const who = language === 'jikiscript' ? 'Jiki' : 'We'
let errorHeading
if (error instanceof SyntaxError) {
errorHeading = "Jiki couldn't understand your code"
errorHeading = `${who} couldn't understand your code`
} else if (error.type == 'LogicError') {
errorHeading = "Something didn't go as expected!"
} else {
errorHeading = 'Jiki hit a problem running your code.'
errorHeading = `${who} hit a problem running your code.`
}
if (context) {
errorHeading = `${context}: ${errorHeading}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function execJS(
} catch (err: any) {
return {
status: 'error',
cleanup: () => {},
cleanup: () => { },
error: {
message: err.message.replace(/\s*\(\d+:\d+\)$/, ''),
lineNumber: err.loc.line - 1, // No idea why we are 2 out.
Expand Down Expand Up @@ -79,8 +79,8 @@ export async function execJS(
}
return successResult
} catch (error: any) {
let lineNumber
let colNumber
let lineNumber: string
let colNumber: string

if (error.name === 'JikiLogicError') {
;[, lineNumber, colNumber] = extractLineColFromJikiLogicError(error)
Expand All @@ -89,6 +89,9 @@ export async function execJS(
;[, lineNumber, colNumber] =
error.stack?.match(/:(\d+):(\d+)\)?\s*$/m) || []
}
if (error.message.includes('does not provide an export')) {
error.message = `Oh dear, we couldn't find \`${fnName}\`. Did you forget to \`export\` it?`
}

const execError: ExecError = {
status: 'error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function showError({
from = Math.max(0, error.location.absolute.begin - 1)
to = Math.max(0, error.location.absolute.end - 1)
line = error.location.line
html = describeError(error, context)
html = describeError(error, 'jikiscript', context)
} else {
// Codemirror requires a 1-based line number, while Js's error output generates a 0-based line number
const lineNumber = error.lineNumber + 1
Expand All @@ -61,12 +61,15 @@ export function showError({
from = pos - 1
to = pos
line = lineNumber
html = describeError({
// @ts-expect-error - partial StaticError-like structure
// TODO: adjust types in describeError
type: error.type,
message: error.message,
})
html = describeError(
{
// @ts-expect-error - partial StaticError-like structure
// TODO: adjust types in describeError
type: error.type,
message: error.message,
},
'javascript'
)
}

scrollToLine(editorView, line)
Expand Down
Loading