mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 08:39:02 +03:00
fix(cli): report run server connection errors as JSON (#59366)
Co-authored-by: andreivince <andreivince21@gmail.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
4371c29b5b
commit
0ec4d0f862
@@ -5,9 +5,13 @@ import { ServerConnection } from "../../services/server-connection"
|
||||
|
||||
export default Runtime.handler(Commands.commands.run, (input) =>
|
||||
Effect.gen(function* () {
|
||||
const { runNonInteractive } = yield* Effect.promise(() => import("../../run/run"))
|
||||
const { reportRunError, runNonInteractive } = yield* Effect.promise(() => import("../../run/run"))
|
||||
const separator = process.argv.indexOf("--", 2)
|
||||
const server = yield* ServerConnection.resolve()
|
||||
const server = yield* ServerConnection.resolve().pipe(
|
||||
Effect.tapError((error) => Effect.logError("run could not resolve its server", { cause: error })),
|
||||
Effect.catch((error) => Effect.sync(() => reportRunError(input, error.message))),
|
||||
)
|
||||
if (!server) return
|
||||
yield* Effect.promise(() =>
|
||||
runNonInteractive({
|
||||
server,
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Server as ServerFlag, Standalone as StandaloneFlag } from "../commands/
|
||||
import { Env } from "../env"
|
||||
import { ServiceConfig } from "./service-config"
|
||||
import { Standalone } from "./standalone"
|
||||
import { errorMessage } from "../util/error"
|
||||
|
||||
export type Args = {
|
||||
readonly server?: string
|
||||
@@ -98,8 +99,11 @@ function connectError(endpoint: Endpoint, cause: unknown) {
|
||||
)
|
||||
}
|
||||
if (cause instanceof ClientError && cause.reason === "Transport")
|
||||
return new Error(`Could not reach server at ${endpoint.url}`, { cause })
|
||||
return new Error(`Server at ${endpoint.url} did not provide a compatible V2 health response`, { cause })
|
||||
return new Error(`Could not reach server at ${endpoint.url}: ${errorMessage(cause.cause ?? cause)}`, { cause })
|
||||
return new Error(
|
||||
`Server at ${endpoint.url} did not provide a compatible V2 health response: ${errorMessage(cause)}`,
|
||||
{ cause },
|
||||
)
|
||||
}
|
||||
|
||||
export * as ServerConnection from "./server-connection"
|
||||
|
||||
@@ -228,6 +228,20 @@ describe("mini command", () => {
|
||||
}
|
||||
})
|
||||
|
||||
test("reports server connection errors as JSON", async () => {
|
||||
const result = await cli(["run", "--format", "json", "--server", "http://127.0.0.1:1", "hi"])
|
||||
|
||||
expect(result.exitCode).toBe(1)
|
||||
expect(JSON.parse(result.stdout)).toMatchObject({
|
||||
type: "error",
|
||||
sessionID: "",
|
||||
error: {
|
||||
type: "unknown",
|
||||
message: expect.stringMatching(/^Could not reach server at http:\/\/127\.0\.0\.1:1: \S/),
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test("uses the shared V2 server option instead of an attach command", async () => {
|
||||
const result = await cli(["mini", "--help"])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user