fix(core): preserve structured error messages (#33530)
This commit is contained in:
parent
10f6bb7878
commit
c17b9557f1
11 changed files with 73 additions and 9 deletions
|
|
@ -1078,6 +1078,11 @@ export class ModelNotFoundError extends Schema.TaggedErrorClass<ModelNotFoundErr
|
|||
suggestions: Schema.optional(Schema.Array(Schema.String)),
|
||||
cause: Schema.optional(Schema.Defect()),
|
||||
}) {
|
||||
override get message() {
|
||||
const suggestions = this.suggestions?.length ? ` Did you mean: ${this.suggestions.join(", ")}?` : ""
|
||||
return `Model not found: ${this.providerID}/${this.modelID}.${suggestions}`
|
||||
}
|
||||
|
||||
static isInstance(input: unknown): input is ModelNotFoundError {
|
||||
return input instanceof ModelNotFoundError
|
||||
}
|
||||
|
|
@ -1087,12 +1092,20 @@ export class InitError extends Schema.TaggedErrorClass<InitError>()("ProviderIni
|
|||
providerID: ProviderV2.ID,
|
||||
cause: Schema.optional(Schema.Defect()),
|
||||
}) {
|
||||
override get message() {
|
||||
return `Failed to initialize provider: ${this.providerID}`
|
||||
}
|
||||
|
||||
static isInstance(input: unknown): input is InitError {
|
||||
return input instanceof InitError
|
||||
}
|
||||
}
|
||||
|
||||
export class NoProvidersError extends Schema.TaggedErrorClass<NoProvidersError>()("ProviderNoProvidersError", {}) {
|
||||
override get message() {
|
||||
return "No providers are available"
|
||||
}
|
||||
|
||||
static isInstance(input: unknown): input is NoProvidersError {
|
||||
return input instanceof NoProvidersError
|
||||
}
|
||||
|
|
@ -1101,6 +1114,10 @@ export class NoProvidersError extends Schema.TaggedErrorClass<NoProvidersError>(
|
|||
export class NoModelsError extends Schema.TaggedErrorClass<NoModelsError>()("ProviderNoModelsError", {
|
||||
providerID: ProviderV2.ID,
|
||||
}) {
|
||||
override get message() {
|
||||
return `No models are available for provider: ${this.providerID}`
|
||||
}
|
||||
|
||||
static isInstance(input: unknown): input is NoModelsError {
|
||||
return input instanceof NoModelsError
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1016,6 +1016,8 @@ it.instance("ModelNotFoundError includes suggestions for typos", () =>
|
|||
.pipe(Effect.flip)
|
||||
expect(error.suggestions).toBeDefined()
|
||||
expect((error.suggestions ?? []).length).toBeGreaterThan(0)
|
||||
expect(error.message).toContain("Model not found: anthropic/claude-sonet-4")
|
||||
expect(error.message).toContain("Did you mean:")
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue