• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

source-academy / js-slang / 24868044425

24 Apr 2026 01:47AM UTC coverage: 78.522% (+0.1%) from 78.391%
24868044425

push

github

web-flow
Error Handling and Stringify Changes (#1893)

* Modify stringify to prioritize toReplString

* Make the extract declarations helper actually work

* Add ability to change loader for source modules

* Add a new option for controlling how Source modules are loaded

* Improve typing for CSE machine

* Add ability to check if modules are loaded with the wrong Source chapter

* Refactor errors to extend from Error class

* Refactor modules errors

* Refactor parser errors

* Refactor cse machine errors

* Mostly fix error handling in the tracer

* Tidy up generator and explainer implementations for tracer

* Remove unnecessary imports and type guards

* Adjust rttc checks to be type guards instead of returning errors

* Adjust miscellanous error changes

* Add eslint rule for useless constructor

* Fix incorrect ordering for checking exceptionerrors

* Minor changes

* Run format

* Run linting

* Override the message property, but also enable noImplicitOverride to prevent accidental overriding

* Add some documentation to some errors

* Add errors to possible imports for modules

* Update getIds helper

* Minor fix to test case

* Run format

* Allow modules to try and load the context of other modules without crashing

* Fix incorrect stdlib name

* Add some more functions to the stdlib list library

* Change to use GeneralRuntimeError for list

* Revert "Change to use GeneralRuntimeError for list"

This reverts commit 642bd99e6.

* Update src/errors/errors.ts

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* Add ability to change manifest and docs importers

* Change how external builtins are defined

* Fix typings and list lib overloads

* Miscellanous changes

* Add the Source equality function to stdlib/misc

* Merge from main branch for tracer

* Add handling for the new importers

* Change errors and made redex a local variable

* Improve tracer typing

* Relocate... (continued)

3125 of 4193 branches covered (74.53%)

Branch coverage included in aggregate %.

899 of 1089 new or added lines in 96 files covered. (82.55%)

21 existing lines in 12 files now uncovered.

7031 of 8741 relevant lines covered (80.44%)

185057.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.63
/src/runner/sourceRunner.ts
1
import type { RawSourceMap } from 'source-map';
2

3
import { JSSLANG_PROPERTIES } from '../constants';
4
import { CSEResultPromise, evaluate as CSEvaluate } from '../cse-machine/interpreter';
5
import { ExceptionError } from '../errors/errors';
6
import { TimeoutError } from '../errors/timeoutErrors';
7
import { getSteps } from '../stepper/steppers';
8
import { sandboxedEval } from '../transpiler/evalContainer';
9
import { transpile } from '../transpiler/transpiler';
10
import { SourceErrorWithNode } from '../errors/base';
11
import { toSourceError } from './errors';
12
import fullJSRunner from './fullJSRunner';
13
import type { Runner } from './types';
14

15
let isPreviousCodeTimeoutError = false;
55✔
16
const runners = {
55✔
17
  fulljs: fullJSRunner,
18
  'cse-machine': (program, context, options) => {
19
    const value = CSEvaluate(program, context, options);
935✔
20
    return CSEResultPromise(context, value);
935✔
21
  },
22
  substitution: (program, context, options) => {
23
    const steps = getSteps(program, context, options);
×
24
    if (context.errors.length > 0) {
×
25
      return Promise.resolve({ status: 'error', context });
×
26
    }
27
    return Promise.resolve({
×
28
      status: 'finished',
29
      context,
30
      value: steps,
31
    });
32
  },
33
  native: async (program, context, options) => {
34
    if (!options.isPrelude) {
709✔
35
      if (context.shouldIncreaseEvaluationTimeout && isPreviousCodeTimeoutError) {
412✔
36
        context.nativeStorage.maxExecTime *= JSSLANG_PROPERTIES.factorToIncreaseBy;
3✔
37
      } else {
38
        context.nativeStorage.maxExecTime = options.originalMaxExecTime;
409✔
39
      }
40
    }
41

42
    let sourceMapJson: RawSourceMap | undefined;
43
    try {
709✔
44
      let transpiled: string;
45
      ({ transpiled, sourceMapJson } = transpile(program, context, options.isPrelude));
709✔
46

47
      let value = sandboxedEval(transpiled, context.nativeStorage);
709✔
48

49
      if (!options.isPrelude) {
709✔
50
        isPreviousCodeTimeoutError = false;
345✔
51
      }
52

53
      return {
642✔
54
        status: 'finished',
55
        context,
56
        value,
57
      };
58
    } catch (error) {
59
      if (error instanceof ExceptionError) {
67✔
60
        // if we know the location of the error, just throw it
61
        if (error.location.start.line !== -1) {
9!
UNCOV
62
          context.errors.push(error);
×
UNCOV
63
          return { status: 'error', context };
×
64
        } else {
65
          error = error.error; // else we try to get the location from source map
9✔
66
        }
67
      }
68

69
      if (error instanceof SourceErrorWithNode) {
67✔
70
        if (error instanceof TimeoutError) {
55✔
71
          isPreviousCodeTimeoutError = true;
7✔
72
        }
73

74
        context.errors.push(error);
55✔
75
        return { status: 'error', context };
55✔
76
      }
77

78
      const sourceError = await toSourceError(error, sourceMapJson);
12✔
79
      context.errors.push(sourceError);
12✔
80
      return { status: 'error', context };
12✔
81
    }
82
  },
83
} satisfies Record<string, Runner>;
84

85
export default runners;
86

87
export type RunnerTypes = keyof typeof runners;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc