fix(ui): show workspace launch errors in dialog
This commit is contained in:
@@ -35,6 +35,7 @@ import { upsertPermissionV2, removePermissionV2, upsertQuestionV2, removeQuestio
|
||||
import { clearCacheForInstance } from "../lib/global-cache"
|
||||
import { getLogger } from "../lib/logger"
|
||||
import { mergeInstanceMetadata, clearInstanceMetadata } from "./instance-metadata"
|
||||
import { showWorkspaceLaunchError } from "./launch-errors"
|
||||
|
||||
const log = getLogger("api")
|
||||
|
||||
@@ -372,6 +373,7 @@ function handleWorkspaceEvent(event: WorkspaceEventPayload) {
|
||||
break
|
||||
case "workspace.error":
|
||||
upsertWorkspace(event.workspace)
|
||||
showWorkspaceLaunchError(event.workspace)
|
||||
break
|
||||
case "workspace.stopped":
|
||||
releaseInstanceResources(event.workspaceId)
|
||||
|
||||
53
packages/ui/src/stores/launch-errors.ts
Normal file
53
packages/ui/src/stores/launch-errors.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { createSignal } from "solid-js"
|
||||
import type { WorkspaceDescriptor } from "../../../server/src/api-types"
|
||||
import { tGlobal } from "../lib/i18n"
|
||||
import { formatLaunchErrorMessage, isMissingBinaryMessage } from "../lib/launch-errors"
|
||||
|
||||
type LaunchErrorSource = "create" | "workspace"
|
||||
|
||||
export interface LaunchErrorState {
|
||||
source: LaunchErrorSource
|
||||
message: string
|
||||
binaryPath: string
|
||||
missingBinary: boolean
|
||||
instanceId?: string
|
||||
}
|
||||
|
||||
const [launchError, setLaunchError] = createSignal<LaunchErrorState | null>(null)
|
||||
|
||||
// Avoid spamming the user with the same modal on repeated events.
|
||||
const lastWorkspaceErrorByInstanceId = new Map<string, string>()
|
||||
|
||||
export function showLaunchError(next: LaunchErrorState) {
|
||||
setLaunchError(next)
|
||||
}
|
||||
|
||||
export function clearLaunchError() {
|
||||
setLaunchError(null)
|
||||
}
|
||||
|
||||
export function showWorkspaceLaunchError(workspace: WorkspaceDescriptor) {
|
||||
const instanceId = workspace.id
|
||||
const rawMessage = workspace.error
|
||||
const message = formatLaunchErrorMessage(rawMessage, tGlobal("app.launchError.fallbackMessage"))
|
||||
|
||||
const previous = lastWorkspaceErrorByInstanceId.get(instanceId)
|
||||
if (previous && previous === message) {
|
||||
return
|
||||
}
|
||||
|
||||
lastWorkspaceErrorByInstanceId.set(instanceId, message)
|
||||
|
||||
const binaryPath = (workspace.binaryLabel || workspace.binaryId || "opencode").trim() || "opencode"
|
||||
const missingBinary = isMissingBinaryMessage(message)
|
||||
|
||||
showLaunchError({
|
||||
source: "workspace",
|
||||
instanceId,
|
||||
message,
|
||||
binaryPath,
|
||||
missingBinary,
|
||||
})
|
||||
}
|
||||
|
||||
export { launchError }
|
||||
Reference in New Issue
Block a user