modestbench 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +21 -19
  3. package/dist/bootstrap.cjs +0 -2
  4. package/dist/bootstrap.cjs.map +1 -1
  5. package/dist/bootstrap.d.cts.map +1 -1
  6. package/dist/bootstrap.d.ts.map +1 -1
  7. package/dist/bootstrap.js +0 -2
  8. package/dist/bootstrap.js.map +1 -1
  9. package/dist/cli/commands/history.cjs +2 -1
  10. package/dist/cli/commands/history.cjs.map +1 -1
  11. package/dist/cli/commands/history.d.cts.map +1 -1
  12. package/dist/cli/commands/history.d.ts.map +1 -1
  13. package/dist/cli/commands/history.js +2 -1
  14. package/dist/cli/commands/history.js.map +1 -1
  15. package/dist/cli/commands/init.cjs +5 -4
  16. package/dist/cli/commands/init.cjs.map +1 -1
  17. package/dist/cli/commands/init.d.cts.map +1 -1
  18. package/dist/cli/commands/init.d.ts.map +1 -1
  19. package/dist/cli/commands/init.js +5 -4
  20. package/dist/cli/commands/init.js.map +1 -1
  21. package/dist/cli/commands/run.cjs +28 -3
  22. package/dist/cli/commands/run.cjs.map +1 -1
  23. package/dist/cli/commands/run.d.cts.map +1 -1
  24. package/dist/cli/commands/run.d.ts.map +1 -1
  25. package/dist/cli/commands/run.js +28 -3
  26. package/dist/cli/commands/run.js.map +1 -1
  27. package/dist/cli/index.cjs +38 -14
  28. package/dist/cli/index.cjs.map +1 -1
  29. package/dist/cli/index.d.cts +1 -2
  30. package/dist/cli/index.d.cts.map +1 -1
  31. package/dist/cli/index.d.ts +1 -2
  32. package/dist/cli/index.d.ts.map +1 -1
  33. package/dist/cli/index.js +33 -9
  34. package/dist/cli/index.js.map +1 -1
  35. package/dist/config/manager.cjs +9 -3
  36. package/dist/config/manager.cjs.map +1 -1
  37. package/dist/config/manager.d.cts.map +1 -1
  38. package/dist/config/manager.d.ts.map +1 -1
  39. package/dist/config/manager.js +9 -3
  40. package/dist/config/manager.js.map +1 -1
  41. package/dist/constants.cjs +53 -1
  42. package/dist/constants.cjs.map +1 -1
  43. package/dist/constants.d.cts +36 -0
  44. package/dist/constants.d.cts.map +1 -1
  45. package/dist/constants.d.ts +36 -0
  46. package/dist/constants.d.ts.map +1 -1
  47. package/dist/constants.js +52 -0
  48. package/dist/constants.js.map +1 -1
  49. package/dist/core/engine.cjs +19 -42
  50. package/dist/core/engine.cjs.map +1 -1
  51. package/dist/core/engine.d.cts +1 -3
  52. package/dist/core/engine.d.cts.map +1 -1
  53. package/dist/core/engine.d.ts +1 -3
  54. package/dist/core/engine.d.ts.map +1 -1
  55. package/dist/core/engine.js +19 -42
  56. package/dist/core/engine.js.map +1 -1
  57. package/dist/core/engines/accurate-engine.cjs +2 -1
  58. package/dist/core/engines/accurate-engine.cjs.map +1 -1
  59. package/dist/core/engines/accurate-engine.d.cts.map +1 -1
  60. package/dist/core/engines/accurate-engine.d.ts.map +1 -1
  61. package/dist/core/engines/accurate-engine.js +2 -1
  62. package/dist/core/engines/accurate-engine.js.map +1 -1
  63. package/dist/core/engines/tinybench-engine.cjs +6 -5
  64. package/dist/core/engines/tinybench-engine.cjs.map +1 -1
  65. package/dist/core/engines/tinybench-engine.d.cts.map +1 -1
  66. package/dist/core/engines/tinybench-engine.d.ts.map +1 -1
  67. package/dist/core/engines/tinybench-engine.js +6 -5
  68. package/dist/core/engines/tinybench-engine.js.map +1 -1
  69. package/dist/core/loader.cjs +16 -5
  70. package/dist/core/loader.cjs.map +1 -1
  71. package/dist/core/loader.d.cts.map +1 -1
  72. package/dist/core/loader.d.ts.map +1 -1
  73. package/dist/core/loader.js +16 -5
  74. package/dist/core/loader.js.map +1 -1
  75. package/dist/errors/base.cjs +130 -0
  76. package/dist/errors/base.cjs.map +1 -0
  77. package/dist/errors/base.d.cts +97 -0
  78. package/dist/errors/base.d.cts.map +1 -0
  79. package/dist/errors/base.d.ts +97 -0
  80. package/dist/errors/base.d.ts.map +1 -0
  81. package/dist/errors/base.js +124 -0
  82. package/dist/errors/base.js.map +1 -0
  83. package/dist/errors/cli.cjs +58 -0
  84. package/dist/errors/cli.cjs.map +1 -0
  85. package/dist/errors/cli.d.cts +44 -0
  86. package/dist/errors/cli.d.cts.map +1 -0
  87. package/dist/errors/cli.d.ts +44 -0
  88. package/dist/errors/cli.d.ts.map +1 -0
  89. package/dist/errors/cli.js +52 -0
  90. package/dist/errors/cli.js.map +1 -0
  91. package/dist/errors/configuration.cjs +48 -0
  92. package/dist/errors/configuration.cjs.map +1 -0
  93. package/dist/errors/configuration.d.cts +41 -0
  94. package/dist/errors/configuration.d.cts.map +1 -0
  95. package/dist/errors/configuration.d.ts +41 -0
  96. package/dist/errors/configuration.d.ts.map +1 -0
  97. package/dist/errors/configuration.js +41 -0
  98. package/dist/errors/configuration.js.map +1 -0
  99. package/dist/errors/execution.cjs +65 -0
  100. package/dist/errors/execution.cjs.map +1 -0
  101. package/dist/errors/execution.d.cts +56 -0
  102. package/dist/errors/execution.d.cts.map +1 -0
  103. package/dist/errors/execution.d.ts +56 -0
  104. package/dist/errors/execution.d.ts.map +1 -0
  105. package/dist/errors/execution.js +56 -0
  106. package/dist/errors/execution.js.map +1 -0
  107. package/dist/errors/file.cjs +56 -0
  108. package/dist/errors/file.cjs.map +1 -0
  109. package/dist/errors/file.d.cts +48 -0
  110. package/dist/errors/file.d.cts.map +1 -0
  111. package/dist/errors/file.d.ts +48 -0
  112. package/dist/errors/file.d.ts.map +1 -0
  113. package/dist/errors/file.js +48 -0
  114. package/dist/errors/file.js.map +1 -0
  115. package/dist/errors/index.cjs +59 -0
  116. package/dist/errors/index.cjs.map +1 -0
  117. package/dist/errors/index.d.cts +16 -0
  118. package/dist/errors/index.d.cts.map +1 -0
  119. package/dist/errors/index.d.ts +16 -0
  120. package/dist/errors/index.d.ts.map +1 -0
  121. package/dist/errors/index.js +24 -0
  122. package/dist/errors/index.js.map +1 -0
  123. package/dist/errors/reporter.cjs +38 -0
  124. package/dist/errors/reporter.cjs.map +1 -0
  125. package/dist/errors/reporter.d.cts +32 -0
  126. package/dist/errors/reporter.d.cts.map +1 -0
  127. package/dist/errors/reporter.d.ts +32 -0
  128. package/dist/errors/reporter.d.ts.map +1 -0
  129. package/dist/errors/reporter.js +32 -0
  130. package/dist/errors/reporter.js.map +1 -0
  131. package/dist/errors/storage.cjs +55 -0
  132. package/dist/errors/storage.cjs.map +1 -0
  133. package/dist/errors/storage.d.cts +47 -0
  134. package/dist/errors/storage.d.cts.map +1 -0
  135. package/dist/errors/storage.d.ts +47 -0
  136. package/dist/errors/storage.d.ts.map +1 -0
  137. package/dist/errors/storage.js +47 -0
  138. package/dist/errors/storage.js.map +1 -0
  139. package/dist/errors/validation.cjs +38 -0
  140. package/dist/errors/validation.cjs.map +1 -0
  141. package/dist/errors/validation.d.cts +32 -0
  142. package/dist/errors/validation.d.cts.map +1 -0
  143. package/dist/errors/validation.d.ts +32 -0
  144. package/dist/errors/validation.d.ts.map +1 -0
  145. package/dist/errors/validation.js +32 -0
  146. package/dist/errors/validation.js.map +1 -0
  147. package/dist/index.cjs +3 -4
  148. package/dist/index.cjs.map +1 -1
  149. package/dist/index.d.cts +1 -1
  150. package/dist/index.d.cts.map +1 -1
  151. package/dist/index.d.ts +1 -1
  152. package/dist/index.d.ts.map +1 -1
  153. package/dist/index.js +2 -2
  154. package/dist/index.js.map +1 -1
  155. package/dist/reporters/csv.cjs +3 -2
  156. package/dist/reporters/csv.cjs.map +1 -1
  157. package/dist/reporters/csv.d.cts.map +1 -1
  158. package/dist/reporters/csv.d.ts.map +1 -1
  159. package/dist/reporters/csv.js +3 -2
  160. package/dist/reporters/csv.js.map +1 -1
  161. package/dist/reporters/human.cjs +2 -2
  162. package/dist/reporters/human.js +2 -2
  163. package/dist/reporters/json.cjs +3 -2
  164. package/dist/reporters/json.cjs.map +1 -1
  165. package/dist/reporters/json.d.cts.map +1 -1
  166. package/dist/reporters/json.d.ts.map +1 -1
  167. package/dist/reporters/json.js +3 -2
  168. package/dist/reporters/json.js.map +1 -1
  169. package/dist/reporters/registry.cjs +3 -2
  170. package/dist/reporters/registry.cjs.map +1 -1
  171. package/dist/reporters/registry.d.cts.map +1 -1
  172. package/dist/reporters/registry.d.ts.map +1 -1
  173. package/dist/reporters/registry.js +3 -2
  174. package/dist/reporters/registry.js.map +1 -1
  175. package/dist/reporters/simple.cjs +1 -1
  176. package/dist/reporters/simple.js +1 -1
  177. package/dist/storage/history.cjs +32 -11
  178. package/dist/storage/history.cjs.map +1 -1
  179. package/dist/storage/history.d.cts.map +1 -1
  180. package/dist/storage/history.d.ts.map +1 -1
  181. package/dist/storage/history.js +32 -11
  182. package/dist/storage/history.js.map +1 -1
  183. package/dist/types/interfaces.d.cts +1 -34
  184. package/dist/types/interfaces.d.cts.map +1 -1
  185. package/dist/types/interfaces.d.ts +1 -34
  186. package/dist/types/interfaces.d.ts.map +1 -1
  187. package/package.json +12 -8
  188. package/src/bootstrap.ts +0 -2
  189. package/src/cli/commands/history.ts +3 -1
  190. package/src/cli/commands/init.ts +14 -4
  191. package/src/cli/commands/run.ts +36 -3
  192. package/src/cli/index.ts +41 -15
  193. package/src/config/manager.ts +13 -3
  194. package/src/constants.ts +60 -0
  195. package/src/core/engine.ts +35 -49
  196. package/src/core/engines/accurate-engine.ts +4 -1
  197. package/src/core/engines/tinybench-engine.ts +12 -5
  198. package/src/core/loader.ts +27 -5
  199. package/src/errors/base.ts +152 -0
  200. package/src/errors/cli.ts +59 -0
  201. package/src/errors/configuration.ts +45 -0
  202. package/src/errors/execution.ts +62 -0
  203. package/src/errors/file.ts +53 -0
  204. package/src/errors/index.ts +71 -0
  205. package/src/errors/reporter.ts +35 -0
  206. package/src/errors/storage.ts +52 -0
  207. package/src/errors/validation.ts +35 -0
  208. package/src/index.ts +3 -3
  209. package/src/reporters/csv.ts +4 -2
  210. package/src/reporters/human.ts +2 -2
  211. package/src/reporters/json.ts +4 -2
  212. package/src/reporters/registry.ts +9 -2
  213. package/src/reporters/simple.ts +1 -1
  214. package/src/storage/history.ts +58 -11
  215. package/src/types/interfaces.ts +0 -43
  216. package/dist/core/error-manager.cjs +0 -303
  217. package/dist/core/error-manager.cjs.map +0 -1
  218. package/dist/core/error-manager.d.cts +0 -77
  219. package/dist/core/error-manager.d.cts.map +0 -1
  220. package/dist/core/error-manager.d.ts +0 -77
  221. package/dist/core/error-manager.d.ts.map +0 -1
  222. package/dist/core/error-manager.js +0 -299
  223. package/dist/core/error-manager.js.map +0 -1
  224. package/src/core/error-manager.ts +0 -372
@@ -0,0 +1,152 @@
1
+ /**
2
+ * ModestBench Custom Error System
3
+ *
4
+ * Base error classes providing structured error handling with error codes,
5
+ * documentation URLs, and consistent error display.
6
+ */
7
+
8
+ /**
9
+ * Base URL for error documentation
10
+ */
11
+ const ERROR_DOC_BASE_URL =
12
+ 'https://boneskull.github.io/modestbench/reference/errors';
13
+
14
+ /**
15
+ * Abstract base class for ModestBench aggregate errors
16
+ *
17
+ * Extends AggregateError to support multiple errors with ModestBench error
18
+ * system features.
19
+ */
20
+ export abstract class ModestBenchAggregateError extends AggregateError {
21
+ /**
22
+ * Unique error code for this error type Must be in format:
23
+ * ERR_MB_CATEGORY_DESCRIPTION
24
+ */
25
+ abstract readonly code: string;
26
+
27
+ /**
28
+ * Error name (matches class name)
29
+ */
30
+ public override readonly name: string;
31
+
32
+ /**
33
+ * Create a new ModestBench aggregate error
34
+ *
35
+ * @param errors - Array of errors that occurred
36
+ * @param message - Human-readable error message
37
+ * @param options - Optional Error options (e.g., cause)
38
+ */
39
+ constructor(errors: unknown[], message: string, options?: ErrorOptions) {
40
+ super(errors, message, options);
41
+ this.name = this.constructor.name;
42
+ }
43
+
44
+ /**
45
+ * Get the documentation URL for this error
46
+ *
47
+ * Returns a URL to the error reference page with an anchor to the specific
48
+ * error.
49
+ *
50
+ * @returns Documentation URL
51
+ */
52
+ getDocUrl(): string {
53
+ // Use the error class name as the anchor (e.g., ConfigValidationError -> #configvalidationerror)
54
+ const anchor = this.name.toLowerCase();
55
+ return `${ERROR_DOC_BASE_URL}#${anchor}`;
56
+ }
57
+
58
+ /**
59
+ * Convert error to string with code, documentation URL, and nested errors
60
+ *
61
+ * @returns Formatted error string
62
+ */
63
+ override toString(): string {
64
+ let result = `${this.name} [${this.code}]: ${this.message}\n`;
65
+ result += `See: ${this.getDocUrl()}\n`;
66
+
67
+ if (this.errors.length > 0) {
68
+ result += `\nContains ${this.errors.length} error(s):\n`;
69
+ this.errors.forEach((err, index) => {
70
+ const errMsg = err instanceof Error ? err.message : String(err);
71
+ result += ` ${index + 1}. ${errMsg}\n`;
72
+ });
73
+ }
74
+
75
+ return result;
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Abstract base class for all ModestBench errors
81
+ *
82
+ * Provides:
83
+ *
84
+ * - Unique error codes with ERR_MB_ prefix
85
+ * - Documentation URL generation
86
+ * - Consistent error display format
87
+ * - TypeScript type safety
88
+ */
89
+ export abstract class ModestBenchError extends Error {
90
+ /**
91
+ * Unique error code for this error type Must be in format:
92
+ * ERR_MB_CATEGORY_DESCRIPTION
93
+ */
94
+ abstract readonly code: string;
95
+
96
+ /**
97
+ * Error name (matches class name)
98
+ */
99
+ public override readonly name: string;
100
+
101
+ /**
102
+ * Create a new ModestBench error
103
+ *
104
+ * @param message - Human-readable error message
105
+ * @param options - Optional Error options (e.g., cause)
106
+ */
107
+ constructor(message: string, options?: ErrorOptions) {
108
+ super(message, options);
109
+ this.name = this.constructor.name;
110
+ }
111
+
112
+ /**
113
+ * Get the documentation URL for this error
114
+ *
115
+ * Returns a URL to the error reference page with an anchor to the specific
116
+ * error.
117
+ *
118
+ * @returns Documentation URL
119
+ */
120
+ getDocUrl(): string {
121
+ // Use the error class name as the anchor (e.g., ConfigValidationError -> #configvalidationerror)
122
+ const anchor = this.name.toLowerCase();
123
+ return `${ERROR_DOC_BASE_URL}#${anchor}`;
124
+ }
125
+
126
+ /**
127
+ * Convert error to string with code and documentation URL
128
+ *
129
+ * @returns Formatted error string
130
+ */
131
+ override toString(): string {
132
+ return `${this.name} [${this.code}]: ${this.message}\nSee: ${this.getDocUrl()}`;
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Type guard to check if an error is a ModestBench error
138
+ *
139
+ * @param error - The error to check
140
+ * @returns True if the error is a ModestBench error
141
+ */
142
+ export const isModestBenchError = (
143
+ error: unknown,
144
+ ): error is ModestBenchError => {
145
+ return (
146
+ typeof error === 'object' &&
147
+ error !== null &&
148
+ 'code' in error &&
149
+ typeof (error as { code: unknown }).code === 'string' &&
150
+ (error as { code: string }).code.startsWith('ERR_MB_')
151
+ );
152
+ };
@@ -0,0 +1,59 @@
1
+ /**
2
+ * CLI-related errors
3
+ *
4
+ * Errors that occur during command-line interface operations.
5
+ */
6
+
7
+ import { ModestBenchError } from './base.js';
8
+
9
+ /**
10
+ * Invalid CLI argument
11
+ *
12
+ * Thrown when a CLI argument is invalid or cannot be parsed.
13
+ */
14
+ export class InvalidArgumentError extends ModestBenchError {
15
+ readonly code = 'ERR_MB_CLI_INVALID_ARGUMENT';
16
+ }
17
+
18
+ /**
19
+ * Invalid date format
20
+ *
21
+ * Thrown when a date string cannot be parsed into a valid date.
22
+ */
23
+ export class InvalidDateFormatError extends ModestBenchError {
24
+ readonly code = 'ERR_MB_CLI_INVALID_DATE_FORMAT';
25
+ }
26
+
27
+ /**
28
+ * Unknown error
29
+ *
30
+ * Thrown at the CLI boundary to wrap unexpected errors that are not ModestBench
31
+ * errors. This ensures all errors have proper structure and documentation
32
+ * links.
33
+ */
34
+ export class UnknownError extends ModestBenchError {
35
+ readonly code = 'ERR_MB_UNKNOWN';
36
+
37
+ /**
38
+ * Create a new UnknownError wrapping an unexpected error
39
+ *
40
+ * @param message - The error message (typically from the original error)
41
+ * @param options - Error options with the original error as the cause
42
+ */
43
+ constructor(message: string, options: ErrorOptions) {
44
+ super(message, options);
45
+ }
46
+
47
+ /**
48
+ * Override toString to show full details of the wrapped error
49
+ */
50
+ override toString(): string {
51
+ let result = super.toString();
52
+
53
+ if (this.cause instanceof Error && this.cause.stack) {
54
+ result += '\n\nOriginal error:\n' + this.cause.stack;
55
+ }
56
+
57
+ return result;
58
+ }
59
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Configuration-related errors
3
+ *
4
+ * Errors that occur during configuration file loading, parsing, and validation.
5
+ */
6
+
7
+ import { ModestBenchError } from './base.js';
8
+
9
+ /**
10
+ * Failed to load configuration
11
+ *
12
+ * Thrown when configuration loading fails for reasons other than file not found
13
+ * (e.g., parse errors, module loading errors).
14
+ */
15
+ export class ConfigLoadError extends ModestBenchError {
16
+ readonly code = 'ERR_MB_CONFIG_LOAD_FAILED';
17
+ }
18
+
19
+ /**
20
+ * Configuration file not found
21
+ *
22
+ * Thrown when a specified configuration file cannot be found.
23
+ */
24
+ export class ConfigNotFoundError extends ModestBenchError {
25
+ readonly code = 'ERR_MB_CONFIG_NOT_FOUND';
26
+ }
27
+
28
+ /**
29
+ * Configuration validation failed
30
+ *
31
+ * Thrown when a configuration file or configuration options fail schema
32
+ * validation.
33
+ */
34
+ export class ConfigValidationError extends ModestBenchError {
35
+ readonly code = 'ERR_MB_CONFIG_VALIDATION_FAILED';
36
+ }
37
+
38
+ /**
39
+ * Unsupported configuration format
40
+ *
41
+ * Thrown when attempting to use an unsupported configuration file format.
42
+ */
43
+ export class UnsupportedConfigFormatError extends ModestBenchError {
44
+ readonly code = 'ERR_MB_CONFIG_UNSUPPORTED_FORMAT';
45
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Execution-related errors
3
+ *
4
+ * Errors that occur during benchmark execution, setup, and teardown.
5
+ */
6
+
7
+ import { ModestBenchError } from './base.js';
8
+
9
+ /**
10
+ * Benchmark execution failed
11
+ *
12
+ * Thrown when overall benchmark execution fails.
13
+ */
14
+ export class BenchmarkExecutionError extends ModestBenchError {
15
+ readonly code = 'ERR_MB_EXECUTION_BENCHMARK_FAILED';
16
+ }
17
+
18
+ /**
19
+ * Operation too fast to measure
20
+ *
21
+ * Thrown when a benchmark operation executes so quickly that it cannot be
22
+ * reliably measured (typically < 1ns per operation).
23
+ */
24
+ export class OperationTooFastError extends ModestBenchError {
25
+ readonly code = 'ERR_MB_EXECUTION_TOO_FAST';
26
+ }
27
+
28
+ /**
29
+ * Setup function failed
30
+ *
31
+ * Thrown when a benchmark setup function fails.
32
+ */
33
+ export class SetupError extends ModestBenchError {
34
+ readonly code = 'ERR_MB_EXECUTION_SETUP_FAILED';
35
+ }
36
+
37
+ /**
38
+ * Task execution failed
39
+ *
40
+ * Thrown when a specific benchmark task fails during execution.
41
+ */
42
+ export class TaskExecutionError extends ModestBenchError {
43
+ readonly code = 'ERR_MB_EXECUTION_TASK_FAILED';
44
+ }
45
+
46
+ /**
47
+ * Teardown function failed
48
+ *
49
+ * Thrown when a benchmark teardown function fails.
50
+ */
51
+ export class TeardownError extends ModestBenchError {
52
+ readonly code = 'ERR_MB_EXECUTION_TEARDOWN_FAILED';
53
+ }
54
+
55
+ /**
56
+ * Execution timeout exceeded
57
+ *
58
+ * Thrown when a benchmark operation exceeds the configured timeout.
59
+ */
60
+ export class TimeoutError extends ModestBenchError {
61
+ readonly code = 'ERR_MB_EXECUTION_TIMEOUT';
62
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * File-related errors
3
+ *
4
+ * Errors that occur during file discovery, loading, and access.
5
+ */
6
+
7
+ import { ModestBenchError } from './base.js';
8
+
9
+ /**
10
+ * File discovery failed
11
+ *
12
+ * Thrown when file discovery/glob pattern matching fails.
13
+ */
14
+ export class FileDiscoveryError extends ModestBenchError {
15
+ readonly code = 'ERR_MB_FILE_DISCOVERY_FAILED';
16
+ }
17
+
18
+ /**
19
+ * Failed to load benchmark file
20
+ *
21
+ * Thrown when loading a benchmark file fails (e.g., import errors, syntax
22
+ * errors).
23
+ */
24
+ export class FileLoadError extends ModestBenchError {
25
+ readonly code = 'ERR_MB_FILE_LOAD_FAILED';
26
+ }
27
+
28
+ /**
29
+ * Benchmark file not found
30
+ *
31
+ * Thrown when a benchmark file cannot be found or does not exist.
32
+ */
33
+ export class FileNotFoundError extends ModestBenchError {
34
+ readonly code = 'ERR_MB_FILE_NOT_FOUND';
35
+ }
36
+
37
+ /**
38
+ * File permission denied
39
+ *
40
+ * Thrown when file access is denied due to insufficient permissions.
41
+ */
42
+ export class FilePermissionError extends ModestBenchError {
43
+ readonly code = 'ERR_MB_FILE_PERMISSION_DENIED';
44
+ }
45
+
46
+ /**
47
+ * Unsupported file extension
48
+ *
49
+ * Thrown when attempting to load a file with an unsupported extension.
50
+ */
51
+ export class UnsupportedFileExtensionError extends ModestBenchError {
52
+ readonly code = 'ERR_MB_FILE_UNSUPPORTED_EXTENSION';
53
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * ModestBench Error Classes
3
+ *
4
+ * Custom error classes for structured error handling throughout ModestBench.
5
+ * All errors extend ModestBenchError and include error codes and documentation
6
+ * URLs.
7
+ */
8
+
9
+ // Base error classes and utilities
10
+ export {
11
+ isModestBenchError,
12
+ ModestBenchAggregateError,
13
+ ModestBenchError,
14
+ } from './base.js';
15
+
16
+ // CLI errors
17
+ export {
18
+ InvalidArgumentError,
19
+ InvalidDateFormatError,
20
+ UnknownError,
21
+ } from './cli.js';
22
+
23
+ // Configuration errors
24
+ export {
25
+ ConfigLoadError,
26
+ ConfigNotFoundError,
27
+ ConfigValidationError,
28
+ UnsupportedConfigFormatError,
29
+ } from './configuration.js';
30
+
31
+ // Execution errors
32
+ export {
33
+ BenchmarkExecutionError,
34
+ OperationTooFastError,
35
+ SetupError,
36
+ TaskExecutionError,
37
+ TeardownError,
38
+ TimeoutError,
39
+ } from './execution.js';
40
+
41
+ // File errors
42
+ export {
43
+ FileDiscoveryError,
44
+ FileLoadError,
45
+ FileNotFoundError,
46
+ FilePermissionError,
47
+ UnsupportedFileExtensionError,
48
+ } from './file.js';
49
+
50
+ // Reporter errors
51
+ export {
52
+ ReporterAlreadyRegisteredError,
53
+ ReporterOutputError,
54
+ UnknownReporterError,
55
+ } from './reporter.js';
56
+
57
+ // Storage errors
58
+ export {
59
+ StorageCorruptionError,
60
+ StorageError,
61
+ StorageIndexError,
62
+ StorageSpaceError,
63
+ UnsupportedExportFormatError,
64
+ } from './storage.js';
65
+
66
+ // Validation errors
67
+ export {
68
+ SchemaValidationError,
69
+ StructureValidationError,
70
+ TypeValidationError,
71
+ } from './validation.js';
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Reporter-related errors
3
+ *
4
+ * Errors that occur during reporter operations.
5
+ */
6
+
7
+ import { ModestBenchError } from './base.js';
8
+
9
+ /**
10
+ * Reporter already registered
11
+ *
12
+ * Thrown when attempting to register a reporter with a name that is already in
13
+ * use.
14
+ */
15
+ export class ReporterAlreadyRegisteredError extends ModestBenchError {
16
+ readonly code = 'ERR_MB_REPORTER_ALREADY_REGISTERED';
17
+ }
18
+
19
+ /**
20
+ * Reporter output failed
21
+ *
22
+ * Thrown when a reporter fails to write output.
23
+ */
24
+ export class ReporterOutputError extends ModestBenchError {
25
+ readonly code = 'ERR_MB_REPORTER_OUTPUT_FAILED';
26
+ }
27
+
28
+ /**
29
+ * Unknown reporter
30
+ *
31
+ * Thrown when attempting to use a reporter that is not registered.
32
+ */
33
+ export class UnknownReporterError extends ModestBenchError {
34
+ readonly code = 'ERR_MB_REPORTER_UNKNOWN';
35
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Storage-related errors
3
+ *
4
+ * Errors that occur during history storage operations.
5
+ */
6
+
7
+ import { ModestBenchError } from './base.js';
8
+
9
+ /**
10
+ * Storage data corruption
11
+ *
12
+ * Thrown when stored data is found to be corrupted or invalid.
13
+ */
14
+ export class StorageCorruptionError extends ModestBenchError {
15
+ readonly code = 'ERR_MB_STORAGE_CORRUPTION';
16
+ }
17
+
18
+ /**
19
+ * Storage operation failed
20
+ *
21
+ * Thrown when a general storage operation fails.
22
+ */
23
+ export class StorageError extends ModestBenchError {
24
+ readonly code = 'ERR_MB_STORAGE_FAILED';
25
+ }
26
+
27
+ /**
28
+ * Storage index corruption
29
+ *
30
+ * Thrown when the storage index is corrupted or cannot be read.
31
+ */
32
+ export class StorageIndexError extends ModestBenchError {
33
+ readonly code = 'ERR_MB_STORAGE_INDEX_CORRUPTION';
34
+ }
35
+
36
+ /**
37
+ * Insufficient storage space
38
+ *
39
+ * Thrown when there is insufficient disk space for storage operations.
40
+ */
41
+ export class StorageSpaceError extends ModestBenchError {
42
+ readonly code = 'ERR_MB_STORAGE_INSUFFICIENT_SPACE';
43
+ }
44
+
45
+ /**
46
+ * Unsupported export format
47
+ *
48
+ * Thrown when attempting to export data in an unsupported format.
49
+ */
50
+ export class UnsupportedExportFormatError extends ModestBenchError {
51
+ readonly code = 'ERR_MB_STORAGE_EXPORT_UNSUPPORTED';
52
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Validation-related errors
3
+ *
4
+ * Errors that occur during benchmark file structure and data validation.
5
+ */
6
+
7
+ import { ModestBenchError } from './base.js';
8
+
9
+ /**
10
+ * Schema validation failed
11
+ *
12
+ * Thrown when data fails to validate against a Zod schema or other schema
13
+ * validation.
14
+ */
15
+ export class SchemaValidationError extends ModestBenchError {
16
+ readonly code = 'ERR_MB_VALIDATION_SCHEMA_FAILED';
17
+ }
18
+
19
+ /**
20
+ * Invalid benchmark structure
21
+ *
22
+ * Thrown when a benchmark file has an invalid or unexpected structure.
23
+ */
24
+ export class StructureValidationError extends ModestBenchError {
25
+ readonly code = 'ERR_MB_VALIDATION_STRUCTURE_INVALID';
26
+ }
27
+
28
+ /**
29
+ * Type validation failed
30
+ *
31
+ * Thrown when data fails type validation checks.
32
+ */
33
+ export class TypeValidationError extends ModestBenchError {
34
+ readonly code = 'ERR_MB_VALIDATION_TYPE_FAILED';
35
+ }
package/src/index.ts CHANGED
@@ -14,9 +14,6 @@ export { ModestBenchConfigurationManager } from './config/manager.js';
14
14
  export { ModestBenchEngine } from './core/engine.js';
15
15
  export { AccurateEngine, TinybenchEngine } from './core/engines/index.js';
16
16
 
17
- // Error handling
18
- export { ModestBenchErrorManager } from './core/error-manager.js';
19
-
20
17
  export { BenchmarkFileLoader } from './core/loader.js';
21
18
 
22
19
  // Statistical utilities
@@ -26,6 +23,9 @@ export {
26
23
  type SampleStatistics,
27
24
  } from './core/stats-utils.js';
28
25
 
26
+ // Error classes
27
+ export * from './errors/index.js';
28
+
29
29
  // Progress tracking
30
30
  export { ModestBenchProgressManager } from './progress/manager.js';
31
31
  // Reporters
@@ -17,6 +17,7 @@ import type {
17
17
  TaskResult,
18
18
  } from '../types/index.js';
19
19
 
20
+ import { ReporterOutputError } from '../errors/index.js';
20
21
  import { BaseReporter } from './registry.js';
21
22
 
22
23
  /**
@@ -340,7 +341,7 @@ export class CsvReporter extends BaseReporter {
340
341
  */
341
342
  private async writeToFile(csvContent: string): Promise<void> {
342
343
  if (!this.outputPath) {
343
- throw new Error('Output path not specified');
344
+ throw new ReporterOutputError('Output path not specified');
344
345
  }
345
346
 
346
347
  try {
@@ -351,8 +352,9 @@ export class CsvReporter extends BaseReporter {
351
352
  // Write CSV file
352
353
  writeFileSync(this.outputPath, csvContent, 'utf8');
353
354
  } catch (error) {
354
- throw new Error(
355
+ throw new ReporterOutputError(
355
356
  `Failed to write CSV output to ${this.outputPath}: ${error instanceof Error ? error.message : String(error)}`,
357
+ { cause: error },
356
358
  );
357
359
  }
358
360
  }
@@ -157,7 +157,7 @@ export class HumanReporter extends BaseReporter {
157
157
  );
158
158
  } else {
159
159
  this.printLine(
160
- `${this.colorize('brightCyan', ansiChars.checkmark + ' All tests passed:')} ${this.colorize('brightWhite', String(totalPassed))}`,
160
+ `${this.colorize('brightCyan', ansiChars.checkmark + ' All tasks passed:')} ${this.colorize('brightWhite', String(totalPassed))}`,
161
161
  );
162
162
  }
163
163
  this.printLine(
@@ -317,7 +317,7 @@ export class HumanReporter extends BaseReporter {
317
317
  \x1b[48;5;0m \x1b[48;5;14m \x1b[38;5;237;48;5;45m▄\x1b[38;5;14;48;5;23m▄\x1b[48;5;14m \x1b[38;5;14;48;5;14m▄\x1b[38;5;53;48;5;38m▄\x1b[38;5;44;48;5;23m▄\x1b[38;5;198;48;5;238m▄\x1b[38;5;198;48;5;125m▄\x1b[38;5;23;48;5;14m▄\x1b[48;5;14m \x1b[48;5;0m \x1b[m
318
318
  \x1b[48;5;0m \x1b[48;5;14m \x1b[38;5;30;48;5;38m▄\x1b[38;5;14;48;5;14m▄\x1b[48;5;14m \x1b[38;5;45;48;5;14m▄\x1b[38;5;89;48;5;14m▄\x1b[38;5;89;48;5;89m▄\x1b[38;5;14;48;5;31m▄\x1b[48;5;14m \x1b[38;5;37;48;5;89m▄\x1b[48;5;198m \x1b[38;5;198;48;5;198m▄\x1b[38;5;31;48;5;14m▄\x1b[48;5;14m \x1b[48;5;0m \x1b[m \x1b[2mnode.js:\x1b[m \x1b[36m${run.environment.nodeVersion} \x1b[m
319
319
  \x1b[48;5;0m \x1b[48;5;14m \x1b[38;5;44;48;5;31m▄\x1b[48;5;14m \x1b[38;5;126;48;5;38m▄\x1b[38;5;198;48;5;237m▄\x1b[38;5;237;48;5;37m▄\x1b[48;5;14m \x1b[38;5;14;48;5;14m▄\x1b[38;5;162;48;5;198m▄▄\x1b[38;5;53;48;5;240m▄\x1b[48;5;14m \x1b[48;5;0m \x1b[m \x1b[2mplatform:\x1b[m \x1b[36m${run.environment.platform} ${run.environment.arch} \x1b[m
320
- \x1b[48;5;0m \x1b[38;5;45;48;5;14m▄\x1b[48;5;14m \x1b[38;5;14;48;5;37m▄\x1b[38;5;14;48;5;5m▄\x1b[38;5;14;48;5;44m▄\x1b[48;5;14m \x1b[38;5;45;48;5;14m▄\x1b[48;5;0m \x1b[m \x1b[2mcpu:\x1b[m \x1b[36m${run.environment.cpu.model} \x1b[2m(\x1b[m\x1b[36m${run.environment.cpu.cores} cores) \x1b[m
320
+ \x1b[48;5;0m \x1b[38;5;45;48;5;14m▄\x1b[48;5;14m \x1b[38;5;14;48;5;37m▄\x1b[38;5;14;48;5;5m▄\x1b[38;5;14;48;5;44m▄\x1b[48;5;14m \x1b[38;5;45;48;5;14m▄\x1b[48;5;0m \x1b[m \x1b[2mcpu:\x1b[m \x1b[36m${run.environment.cpu.model} \x1b[2m(\x1b[m\x1b[36m${run.environment.cpu.cores} cores\x1b[2m) \x1b[m
321
321
  \x1b[49;38;5;0m▀▀\x1b[38;5;0;48;5;6m▄\x1b[38;5;232;48;5;14m▄\x1b[38;5;38;48;5;14m▄\x1b[48;5;14m \x1b[38;5;30;48;5;14m▄\x1b[38;5;0;48;5;14m▄\x1b[38;5;0;48;5;23m▄\x1b[49;38;5;0m▀▀\x1b[m \x1b[2mmem:\x1b[m \x1b[36m${this.formatBytes(run.environment.memory.total)} \x1b[m
322
322
  \x1b[49m \x1b[49;38;5;0m▀\x1b[38;5;0;48;5;236m▄\x1b[38;5;0;48;5;45m▄\x1b[38;5;23;48;5;14m▄\x1b[48;5;14m \x1b[38;5;236;48;5;14m▄\x1b[38;5;0;48;5;44m▄\x1b[38;5;0;48;5;232m▄\x1b[49;38;5;0m▀\x1b[49m \x1b[m
323
323
  \x1b[49m \x1b[49;38;5;0m▀▀\x1b[38;5;0;48;5;37m▄\x1b[38;5;0;48;5;14m▄\x1b[38;5;0;48;5;30m▄\x1b[49;38;5;0m▀▀\x1b[49m \x1b[m
@@ -16,6 +16,7 @@ import type {
16
16
  TaskResult,
17
17
  } from '../types/index.js';
18
18
 
19
+ import { ReporterOutputError } from '../errors/index.js';
19
20
  import { BaseReporter } from './registry.js';
20
21
 
21
22
  /**
@@ -266,7 +267,7 @@ export class JsonReporter extends BaseReporter {
266
267
  */
267
268
  private async writeToFile(output: JsonOutput): Promise<void> {
268
269
  if (!this.outputPath) {
269
- throw new Error('Output path not specified');
270
+ throw new ReporterOutputError('Output path not specified');
270
271
  }
271
272
 
272
273
  try {
@@ -281,8 +282,9 @@ export class JsonReporter extends BaseReporter {
281
282
 
282
283
  writeFileSync(this.outputPath, jsonString, 'utf8');
283
284
  } catch (error) {
284
- throw new Error(
285
+ throw new ReporterOutputError(
285
286
  `Failed to write JSON output to ${this.outputPath}: ${error instanceof Error ? error.message : String(error)}`,
287
+ { cause: error },
286
288
  );
287
289
  }
288
290
  }
@@ -15,6 +15,11 @@ import type {
15
15
  TaskResult,
16
16
  } from '../types/index.js';
17
17
 
18
+ import {
19
+ ReporterAlreadyRegisteredError,
20
+ UnknownReporterError,
21
+ } from '../errors/index.js';
22
+
18
23
  /**
19
24
  * Base abstract reporter class providing common functionality
20
25
  */
@@ -301,7 +306,7 @@ export class ModestBenchReporterRegistry implements ReporterRegistry {
301
306
  }
302
307
 
303
308
  if (missing.length > 0) {
304
- throw new Error(
309
+ throw new UnknownReporterError(
305
310
  `Unknown reporters: ${missing.join(', ')}. Available: ${Array.from(this.reporters.keys()).join(', ')}`,
306
311
  );
307
312
  }
@@ -328,7 +333,9 @@ export class ModestBenchReporterRegistry implements ReporterRegistry {
328
333
  */
329
334
  register(name: string, reporter: Reporter): void {
330
335
  if (this.reporters.has(name)) {
331
- throw new Error(`Reporter with name "${name}" is already registered`);
336
+ throw new ReporterAlreadyRegisteredError(
337
+ `Reporter with name "${name}" is already registered`,
338
+ );
332
339
  }
333
340
  this.reporters.set(name, reporter);
334
341
  }