Showing the changes to controller/src/modules (3 of 3 files). Show all
Unified · Split
| @@ -18,6 +18,7 @@ import { DOWNLOAD_DEFAULT_IGNORE_FILENAMES, DOWNLOAD_PROGRESS_THROTTLE_MS } from · 17 unmodified lines | ||
| 18 | 18 | import { EngineOperationError } from "../engine-spec"; |
| 19 | 19 | import type { DownloadFileInfo, DownloadStatus, ModelDownload } from "../types"; |
| 20 | 20 | import type { DownloadStore } from "./download-store"; |
| 21 | +import { attempt, operationError } from "./download-operation"; | |
| 21 | 22 | import { |
| 22 | 23 | buildHuggingFaceFileList, |
| 23 | 24 | fetchEffect, |
| @@ -108,18 +109,6 @@ type ActiveDownload = { · 84 unmodified lines | ||
| 108 | 109 | |
| 109 | 110 | const toTimestamp = (): string => new Date().toISOString(); |
| 110 | 111 | |
| 111 | −const operationError = (operation: string, cause: unknown): EngineOperationError => | |
| 112 | − new EngineOperationError({ | |
| 113 | − operation, | |
| 114 | − message: cause instanceof Error ? cause.message : String(cause), | |
| 115 | − }); | |
| 116 | − | |
| 117 | −const attempt = <A>(operation: string, evaluate: () => A): Effect.Effect<A, EngineOperationError> => | |
| 118 | − Effect.try({ | |
| 119 | − try: evaluate, | |
| 120 | − catch: (cause) => operationError(operation, cause), | |
| 121 | − }); | |
| 122 | − | |
| 123 | 112 | const closeWriter = ( |
| 124 | 113 | writer: ReturnType<typeof createWriteStream>, |
| 125 | 114 | ): Effect.Effect<void, EngineOperationError> => |
| @@ -0,0 +1,14 @@ | ||
| 1 | +import { Effect } from "effect"; | |
| 2 | +import { EngineOperationError } from "../engine-spec"; | |
| 3 | + | |
| 4 | +export const operationError = (operation: string, cause: unknown): EngineOperationError => | |
| 5 | + new EngineOperationError({ | |
| 6 | + operation, | |
| 7 | + message: cause instanceof Error ? cause.message : String(cause), | |
| 8 | + }); | |
| 9 | + | |
| 10 | +export const attempt = <A>(operation: string, evaluate: () => A): Effect.Effect<A, EngineOperationError> => | |
| 11 | + Effect.try({ | |
| 12 | + try: evaluate, | |
| 13 | + catch: (cause) => operationError(operation, cause), | |
| 14 | + }); | |
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | import { Effect, Option, Schema } from "effect"; |
| 2 | 2 | import { openSqliteDatabase } from "../../../stores/sqlite"; |
| 3 | −import { EngineOperationError } from "../engine-spec"; | |
| 3 | +import type { EngineOperationError } from "../engine-spec"; | |
| 4 | 4 | import type { ModelDownload } from "../types"; |
| 5 | +import { attempt, operationError } from "./download-operation"; | |
| 5 | 6 | |
| 6 | 7 | const DownloadFileSchema = Schema.Struct({ |
| 7 | 8 | path: Schema.String, |
| @@ -27,18 +28,6 @@ const ModelDownloadSchema = Schema.Struct({ · 19 unmodified lines | ||
| 27 | 28 | error: Schema.NullOr(Schema.String), |
| 28 | 29 | }); |
| 29 | 30 | |
| 30 | −const operationError = (operation: string, cause: unknown): EngineOperationError => | |
| 31 | − new EngineOperationError({ | |
| 32 | − operation, | |
| 33 | − message: cause instanceof Error ? cause.message : String(cause), | |
| 34 | − }); | |
| 35 | − | |
| 36 | −const attempt = <A>(operation: string, evaluate: () => A): Effect.Effect<A, EngineOperationError> => | |
| 37 | − Effect.try({ | |
| 38 | − try: evaluate, | |
| 39 | − catch: (cause) => operationError(operation, cause), | |
| 40 | − }); | |
| 41 | − | |
| 42 | 31 | const decodeDownload = (value: unknown): Effect.Effect<ModelDownload, EngineOperationError> => |
| 43 | 32 | attempt("parse-download-record", () => |
| 44 | 33 | typeof value === "string" ? JSON.parse(value) : value, |