Unified · Split
| @@ -4,13 +4,13 @@ import type { PlatformError } from "effect/PlatformError"; · 3 unmodified lines | |||
| 4 | import * as jsonc from "jsonc-parser"; | 4 | import * as jsonc from "jsonc-parser"; |
| 5 | import { ExecutorFileConfig } from "./schema"; | 5 | import { ExecutorFileConfig } from "./schema"; |
| 6 | 6 | ||
| 7 | export class ConfigParseError { | 7 | export class ConfigParseError extends Schema.TaggedErrorClass<ConfigParseError>()( |
| 8 | readonly _tag = "ConfigParseError"; | 8 | "ConfigParseError", |
| 9 | constructor( | 9 | { |
| 10 | readonly path: string, | 10 | path: Schema.String, |
| 11 | readonly message: string, | 11 | message: Schema.String, |
| 12 | ) {} | 12 | }, |
| 13 | } | 13 | ) {} |
| 14 | 14 | ||
| 15 | /** | 15 | /** |
| 16 | * Load and validate an executor config file. | 16 | * Load and validate an executor config file. |
| @@ -38,11 +38,17 @@ export const loadConfig = ( · 21 unmodified lines | |||
| 38 | const msg = errors | 38 | const msg = errors |
| 39 | .map((e) => `offset ${e.offset}: ${jsonc.printParseErrorCode(e.error)}`) | 39 | .map((e) => `offset ${e.offset}: ${jsonc.printParseErrorCode(e.error)}`) |
| 40 | .join("; "); | 40 | .join("; "); |
| 41 | return yield* Effect.fail(new ConfigParseError(path, msg)); | 41 | return yield* new ConfigParseError({ path, message: msg }); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | const decoded = yield* Schema.decodeUnknownEffect(ExecutorFileConfig)(parsed).pipe( | 44 | const decoded = yield* Schema.decodeUnknownEffect(ExecutorFileConfig)(parsed).pipe( |
| 45 | Effect.mapError((e) => new ConfigParseError(path, String(e))), | 45 | Effect.mapError( |
| 46 | (error) => | ||
| 47 | new ConfigParseError({ | ||
| 48 | path, | ||
| 49 | message: error.issue.toString(), | ||
| 50 | }), | ||
| 51 | ), | ||
| 46 | ); | 52 | ); |
| 47 | 53 | ||
| 48 | return decoded; | 54 | return decoded; |