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