Skip to content

Commit 5208035

Browse files
authored
JS-error improvements (exercism#7818)
* Add readable missing export error * Adjust error header * Visual tweak
1 parent 8b58302 commit 5208035

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

app/css/bootcamp/components/editor-information-tooltip.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
&.error {
7676
@apply bg-white border-2 border-red-500;
7777

78+
@apply p-0;
79+
7880
filter: drop-shadow(0px 4px 8px rgba(79, 114, 205, 0.5));
7981

8082
h2 {
@@ -89,6 +91,7 @@
8991
}
9092
}
9193
.content {
94+
@apply rounded-6;
9295
@apply text-textColor1;
9396
@apply pt-10 px-20 pb-12;
9497
@apply relative z-tooltip-content bg-white;

app/javascript/components/bootcamp/JikiscriptExercisePage/CodeMirror/extensions/end-line-information/describeError.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ import { marked } from 'marked'
99
import type { StaticError } from '@/interpreter/error'
1010
import { SyntaxError } from '@/interpreter/error'
1111

12-
export function describeError(error: StaticError, context?: string) {
12+
export function describeError(
13+
error: StaticError,
14+
language: 'jikiscript' | 'javascript',
15+
context?: string
16+
) {
17+
const who = language === 'jikiscript' ? 'Jiki' : 'We'
1318
let errorHeading
1419
if (error instanceof SyntaxError) {
15-
errorHeading = "Jiki couldn't understand your code"
20+
errorHeading = `${who} couldn't understand your code`
1621
} else if (error.type == 'LogicError') {
1722
errorHeading = "Something didn't go as expected!"
1823
} else {
19-
errorHeading = 'Jiki hit a problem running your code.'
24+
errorHeading = `${who} hit a problem running your code.`
2025
}
2126
if (context) {
2227
errorHeading = `${context}: ${errorHeading}`

app/javascript/components/bootcamp/JikiscriptExercisePage/test-runner/generateAndRunTestSuite/execJS.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export async function execJS(
3333
} catch (err: any) {
3434
return {
3535
status: 'error',
36-
cleanup: () => {},
36+
cleanup: () => { },
3737
error: {
3838
message: err.message.replace(/\s*\(\d+:\d+\)$/, ''),
3939
lineNumber: err.loc.line - 1, // No idea why we are 2 out.
@@ -79,8 +79,8 @@ export async function execJS(
7979
}
8080
return successResult
8181
} catch (error: any) {
82-
let lineNumber
83-
let colNumber
82+
let lineNumber: string
83+
let colNumber: string
8484

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

9396
const execError: ExecError = {
9497
status: 'error',

app/javascript/components/bootcamp/JikiscriptExercisePage/utils/showError.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function showError({
5151
from = Math.max(0, error.location.absolute.begin - 1)
5252
to = Math.max(0, error.location.absolute.end - 1)
5353
line = error.location.line
54-
html = describeError(error, context)
54+
html = describeError(error, 'jikiscript', context)
5555
} else {
5656
// Codemirror requires a 1-based line number, while Js's error output generates a 0-based line number
5757
const lineNumber = error.lineNumber + 1
@@ -61,12 +61,15 @@ export function showError({
6161
from = pos - 1
6262
to = pos
6363
line = lineNumber
64-
html = describeError({
65-
// @ts-expect-error - partial StaticError-like structure
66-
// TODO: adjust types in describeError
67-
type: error.type,
68-
message: error.message,
69-
})
64+
html = describeError(
65+
{
66+
// @ts-expect-error - partial StaticError-like structure
67+
// TODO: adjust types in describeError
68+
type: error.type,
69+
message: error.message,
70+
},
71+
'javascript'
72+
)
7073
}
7174

7275
scrollToLine(editorView, line)

0 commit comments

Comments
 (0)