feat: add special message for bad indentation (#53744)

This commit is contained in:
Oliver Eyton-Williams
2024-02-21 10:21:55 +01:00
committed by GitHub
parent c4f7549711
commit 522da7ba34
3 changed files with 23 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
// We have to specify pyodide.js because we need to import that file (not .mjs)
// and 'import' defaults to .mjs
import { loadPyodide, type PyodideInterface } from 'pyodide/pyodide.js';
import type { PyProxy } from 'pyodide/ffi';
import type { PyProxy, PythonError } from 'pyodide/ffi';
import pkg from 'pyodide/package.json';
import * as helpers from '@freecodecamp/curriculum-helpers';
import chai from 'chai';
@@ -135,17 +135,22 @@ input = __inputGen(${JSON.stringify(input ?? [])})
// available to the test.
try {
runPython(code);
} catch (err) {
// We don't, yet, want user code to raise exceptions. When they do, we
// count this as a failing test.
ctx.postMessage({
} catch (e) {
const err = e as PythonError;
// Quite a lot of lessons can easily lead users to write code that has
// indentation errors. In these cases we want to provide a more helpful
// error message. For other errors, we can just provide the standard
// message.
const errorType =
err.type === 'IndentationError' ? 'indentation' : 'other';
return ctx.postMessage({
err: {
message: (err as Error).message,
stack: (err as Error).stack,
syntaxError: true
message: err.message,
stack: err.stack,
errorType
}
});
return;
}
// TODO: remove the next line, creating __locals, once all the tests access
// variables directly.