Skip to content

Commit 5a28ebd

Browse files
committed
fix(lint): satisfy effect and unicorn rules for docker port fallback
1 parent ef634ae commit 5a28ebd

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

packages/lib/src/shell/docker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ const parsePublishedHostPortsFromLine = (line: string): ReadonlyArray<number> =>
451451
continue
452452
}
453453
const value = Number.parseInt(rawPort, 10)
454-
if (Number.isInteger(value) && value > 0 && value <= 65535) {
454+
if (Number.isInteger(value) && value > 0 && value <= 65_535) {
455455
parsed.push(value)
456456
}
457457
}
@@ -511,5 +511,5 @@ export const runDockerPsPublishedHostPorts = (
511511
[Number(ExitCode(0))],
512512
(exitCode) => new CommandFailedError({ command: "docker ps", exitCode })
513513
),
514-
Effect.map(parseDockerPublishedHostPorts)
514+
Effect.map((output) => parseDockerPublishedHostPorts(output))
515515
)

packages/lib/src/usecases/ports-reserve.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type * as CommandExecutor from "@effect/platform/CommandExecutor"
22
import type { PlatformError } from "@effect/platform/Error"
33
import type { FileSystem } from "@effect/platform/FileSystem"
44
import * as Path from "@effect/platform/Path"
5-
import { Effect, Option } from "effect"
5+
import { Effect, Either, Option } from "effect"
66

77
import { runDockerPsPublishedHostPorts } from "../shell/docker.js"
88
import { PortProbeError } from "../shell/errors.js"
@@ -47,14 +47,17 @@ const reservePort = (
4747
}
4848

4949
const loadPublishedDockerPorts = (): Effect.Effect<ReadonlySet<number>, never, CommandExecutor.CommandExecutor> =>
50-
runDockerPsPublishedHostPorts(process.cwd()).pipe(
51-
Effect.map((ports) => new Set(ports)),
52-
Effect.catchAll((error) =>
53-
Effect.logWarning(
54-
`Failed to read published Docker ports; falling back to TCP probing only: ${
55-
error instanceof Error ? error.message : String(error)
56-
}`
57-
).pipe(Effect.as(new Set<number>()))
50+
Effect.either(runDockerPsPublishedHostPorts(process.cwd())).pipe(
51+
Effect.flatMap(
52+
Either.match({
53+
onLeft: (error) =>
54+
Effect.logWarning(
55+
`Failed to read published Docker ports; falling back to TCP probing only: ${
56+
error instanceof Error ? error.message : String(error)
57+
}`
58+
).pipe(Effect.as(new Set<number>())),
59+
onRight: (ports) => Effect.succeed(new Set(ports))
60+
})
5861
)
5962
)
6063

0 commit comments

Comments
 (0)