fix(storage): type not found errors (#27265)
This commit is contained in:
@@ -2,8 +2,6 @@ import type { NotFoundError as StorageNotFoundError } from "@/storage/storage"
|
||||
import { Effect } from "effect"
|
||||
import * as ApiError from "../errors"
|
||||
|
||||
type StorageNotFound = InstanceType<typeof StorageNotFoundError>
|
||||
|
||||
export function mapStorageNotFound<A, R>(self: Effect.Effect<A, StorageNotFound, R>) {
|
||||
return self.pipe(Effect.mapError((error) => ApiError.notFound(error.data.message)))
|
||||
export function mapStorageNotFound<A, R>(self: Effect.Effect<A, StorageNotFoundError, R>) {
|
||||
return self.pipe(Effect.mapError((error) => ApiError.notFound(error.message)))
|
||||
}
|
||||
|
||||
@@ -24,11 +24,14 @@ export const errorLayer = HttpRouter.middleware<{ handles: unknown }>()((effect)
|
||||
const error = defect.defect
|
||||
log.error("failed", { error, cause: Cause.pretty(cause) })
|
||||
|
||||
if (error instanceof NotFoundError) {
|
||||
return Effect.succeed(HttpServerResponse.jsonUnsafe(error.toObject(), { status: 404 }))
|
||||
}
|
||||
|
||||
if (error instanceof NamedError) {
|
||||
return Effect.succeed(
|
||||
HttpServerResponse.jsonUnsafe(error.toObject(), {
|
||||
status: iife(() => {
|
||||
if (error instanceof NotFoundError) return 404
|
||||
if (error instanceof Provider.ModelNotFoundError) return 400
|
||||
if (error.name === "ProviderAuthValidationFailed") return 400
|
||||
if (error.name.startsWith("Worktree")) return 400
|
||||
|
||||
@@ -448,7 +448,7 @@ export class BusyError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export type NotFound = InstanceType<typeof NotFoundError>
|
||||
export type NotFound = NotFoundError
|
||||
|
||||
export interface Interface {
|
||||
readonly list: (input?: ListInput) => Effect.Effect<Info[]>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import * as Log from "@opencode-ai/core/util/log"
|
||||
import path from "path"
|
||||
import { Global } from "@opencode-ai/core/global"
|
||||
import { NamedError } from "@opencode-ai/core/util/error"
|
||||
import { AppFileSystem } from "@opencode-ai/core/filesystem"
|
||||
import { Effect, Exit, Layer, Option, RcMap, Schema, Context, TxReentrantLock } from "effect"
|
||||
import { NonNegativeInt } from "@opencode-ai/core/schema"
|
||||
@@ -15,11 +14,22 @@ type Migration = (
|
||||
git: Git.Interface,
|
||||
) => Effect.Effect<void, AppFileSystem.Error>
|
||||
|
||||
export const NotFoundError = NamedError.create("NotFoundError", {
|
||||
export class NotFoundError extends Schema.TaggedErrorClass<NotFoundError>()("NotFoundError", {
|
||||
message: Schema.String,
|
||||
})
|
||||
}) {
|
||||
static isInstance(input: unknown): input is NotFoundError {
|
||||
return input instanceof NotFoundError
|
||||
}
|
||||
|
||||
export type Error = AppFileSystem.Error | InstanceType<typeof NotFoundError>
|
||||
toObject() {
|
||||
return {
|
||||
name: "NotFoundError" as const,
|
||||
data: { message: this.message },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type Error = AppFileSystem.Error | NotFoundError
|
||||
|
||||
const RootFile = Schema.Struct({
|
||||
path: Schema.optional(
|
||||
@@ -245,7 +255,7 @@ export const layer = Layer.effect(
|
||||
}),
|
||||
)
|
||||
|
||||
const fail = (target: string): Effect.Effect<never, InstanceType<typeof NotFoundError>> =>
|
||||
const fail = (target: string): Effect.Effect<never, NotFoundError> =>
|
||||
Effect.fail(new NotFoundError({ message: `Resource not found: ${target}` }))
|
||||
|
||||
const wrap = <A>(target: string, body: Effect.Effect<A, AppFileSystem.Error>) =>
|
||||
|
||||
Reference in New Issue
Block a user