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

source-academy / js-slang / 24834367427

23 Apr 2026 12:09PM UTC coverage: 78.541% (+0.2%) from 78.391%
24834367427

Pull #1893

github

web-flow
Merge ab101147d into 715603479
Pull Request #1893: Error Handling and Stringify Changes

3126 of 4197 branches covered (74.48%)

Branch coverage included in aggregate %.

801 of 975 new or added lines in 76 files covered. (82.15%)

20 existing lines in 11 files now uncovered.

7056 of 8767 relevant lines covered (80.48%)

173930.4 hits per line

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

80.65
/src/errors/base.ts
1
import type es from 'estree';
2
import type { Node } from '../types';
3
import { UNKNOWN_LOCATION } from '../constants';
4

5
export enum ErrorType {
75✔
6
  IMPORT = 'Import',
75✔
7
  RUNTIME = 'Runtime',
75✔
8
  SYNTAX = 'Syntax',
75✔
9
  TYPE = 'Type',
75✔
10
}
11

12
export enum ErrorSeverity {
75✔
13
  WARNING = 'Warning',
75✔
14
  ERROR = 'Error',
75✔
15
}
16

17
// any and all errors ultimately implement this interface. as such, changes to this will affect every type of error.
18
export interface SourceError {
19
  readonly type: ErrorType;
20
  readonly severity: ErrorSeverity;
21

22
  location: es.SourceLocation;
23
  explain(): string;
24
  elaborate(): string;
25
}
26

27
/**
28
 * Abstract Source Error class that automatically handles its location property
29
 */
30
export abstract class SourceErrorWithNode<
31
  T extends es.BaseNode | undefined = es.BaseNode | undefined,
32
>
33
  extends Error
34
  implements SourceError
35
{
36
  constructor(public node: T) {
1,217✔
37
    super();
1,217✔
38
  }
39

40
  public get location() {
41
    return this.node?.loc ?? UNKNOWN_LOCATION;
855✔
42
  }
43

44
  public abstract readonly type: ErrorType;
45
  public abstract readonly severity: ErrorSeverity;
46

47
  public abstract explain(): string;
48
  public abstract elaborate(): string;
49

50
  public override get message() {
51
    return this.explain();
53✔
52
  }
53
}
54

55
/**
56
 * Abstract Source Error class for Runtime errors
57
 */
58
export abstract class RuntimeSourceError<
59
  T extends es.BaseNode | undefined = es.BaseNode | undefined,
60
> extends SourceErrorWithNode<T> {
61
  type = ErrorType.RUNTIME;
1,052✔
62
  severity = ErrorSeverity.ERROR;
1,052✔
63

64
  public override elaborate(): string {
65
    return this.explain();
830✔
66
  }
67
}
68

69
/**
70
 * A concrete instantiation of {@link RuntimeSourceError} that can
71
 * be used when there just aren't any other good Source error classes that can be used
72
 */
73
export class GeneralRuntimeError extends RuntimeSourceError<es.BaseNode | undefined> {
74
  constructor(
75
    private readonly explanation: string,
10✔
76
    node?: es.BaseNode,
77
    private readonly elaboration?: string,
10✔
78
  ) {
79
    super(node);
10✔
80
  }
81

82
  public override explain() {
83
    return this.explanation;
9✔
84
  }
85

86
  public override elaborate() {
NEW
87
    return this.elaboration ?? this.explain();
×
88
  }
89
}
90

91
/**
92
 * A subclass of {@link RuntimeSourceError} intended for use when an unexpected runtime error
93
 * occurs due to an internal error rather than any error caused by the code being evaluated.
94
 */
95
export class InternalRuntimeError<T extends es.BaseNode = Node> extends RuntimeSourceError<
96
  T | undefined
97
> {
98
  constructor(
99
    private readonly explanation: string,
10✔
100
    node?: T,
101
    private readonly elaboration?: string,
10✔
102
  ) {
103
    super(node);
10✔
104
  }
105

106
  public override explain() {
107
    return this.explanation;
13✔
108
  }
109

110
  public override elaborate(): string {
NEW
111
    return this.elaboration ?? this.explain();
×
112
  }
113
}
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