The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Data from "effect/Data"; |
| 2 | import type { PlatformError } from "effect/PlatformError"; |
| 3 | |
| 4 | export class DockerRegistryBlobUnknown extends Data.TaggedError("DockerRegistryBlobUnknown")<{ |
| 5 | readonly cause: PlatformError; |
| 6 | }> { |
| 7 | override get message() { |
| 8 | return this.cause.message; |
| 9 | } |
| 10 | } |
| 11 | |
| 12 | export class DockerRegistryUnavailable extends Data.TaggedError("DockerRegistryUnavailable")<{ |
| 13 | readonly cause: PlatformError; |
| 14 | }> { |
| 15 | override get message() { |
| 16 | return this.cause.message; |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | export type DockerImagePublicationError = |
| 21 | | PlatformError |
| 22 | | DockerRegistryBlobUnknown |
| 23 | | DockerRegistryUnavailable; |
| 24 | |
| 25 | export const classifyDockerRegistryError = (error: PlatformError): DockerImagePublicationError => { |
| 26 | // Build logs can contain arbitrary Dockerfile output before the final error. |
| 27 | const message = |
| 28 | error.reason.description |
| 29 | ?.split("\n") |
| 30 | .map((line) => line.trim()) |
| 31 | .filter( |
| 32 | (line) => |
| 33 | line.length > 0 && |
| 34 | !line.startsWith("View build details: docker-desktop://dashboard/build/"), |
| 35 | ) |
| 36 | .at(-1) ?? ""; |
| 37 | if (/(?:^|:\s*)(?:unknown:\s*)?blob unknown to registry$/i.test(message)) { |
| 38 | return new DockerRegistryBlobUnknown({ cause: error }); |
| 39 | } |
| 40 | if ( |
| 41 | /(?:unexpected (?:http )?status(?:[^\n]*:\s*|\s+)5\d\d(?:\s|$)|(?:^|:\s*)(?:500 internal server error|502 bad gateway|503 service unavailable|504 gateway timeout)$)/i.test( |
| 42 | message, |
| 43 | ) |
| 44 | ) { |
| 45 | return new DockerRegistryUnavailable({ cause: error }); |
| 46 | } |
| 47 | return error; |
| 48 | }; |