fix(provider): type model not found errors (#27334)
This commit is contained in:
@@ -64,6 +64,23 @@ describe("cli.error", () => {
|
||||
expect(formatted).toContain("Check your network, proxy, or VPN configuration and try again.")
|
||||
})
|
||||
|
||||
test("formats legacy and tagged provider model errors the same way", () => {
|
||||
const data = {
|
||||
providerID: "anthropic",
|
||||
modelID: "claude-sonet-4",
|
||||
suggestions: ["claude-sonnet-4"],
|
||||
}
|
||||
const expected = [
|
||||
"Model not found: anthropic/claude-sonet-4",
|
||||
"Did you mean: claude-sonnet-4",
|
||||
"Try: `opencode models` to list available models",
|
||||
"Or check your config (opencode.json) provider/model names",
|
||||
].join("\n")
|
||||
|
||||
expect(FormatError({ name: "ProviderModelNotFoundError", data })).toBe(expected)
|
||||
expect(FormatError({ _tag: "ProviderModelNotFoundError", ...data })).toBe(expected)
|
||||
})
|
||||
|
||||
test("formats cancelled UI errors as empty output", () => {
|
||||
expect(FormatError(new UI.CancelledError())).toBe("")
|
||||
})
|
||||
|
||||
@@ -1572,8 +1572,8 @@ test("ModelNotFoundError includes suggestions for typos", async () => {
|
||||
await getModel(ProviderID.anthropic, ModelID.make("claude-sonet-4")) // typo: sonet instead of sonnet
|
||||
expect(true).toBe(false) // Should not reach here
|
||||
} catch (e: any) {
|
||||
expect(e.data.suggestions).toBeDefined()
|
||||
expect(e.data.suggestions.length).toBeGreaterThan(0)
|
||||
expect(e.suggestions).toBeDefined()
|
||||
expect(e.suggestions.length).toBeGreaterThan(0)
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -1598,8 +1598,8 @@ test("ModelNotFoundError for provider includes suggestions", async () => {
|
||||
await getModel(ProviderID.make("antropic"), ModelID.make("claude-sonnet-4")) // typo: antropic
|
||||
expect(true).toBe(false) // Should not reach here
|
||||
} catch (e: any) {
|
||||
expect(e.data.suggestions).toBeDefined()
|
||||
expect(e.data.suggestions).toContain("anthropic")
|
||||
expect(e.suggestions).toBeDefined()
|
||||
expect(e.suggestions).toContain("anthropic")
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -1625,7 +1625,7 @@ test("ModelNotFoundError suggests catalog models for unloaded providers", async
|
||||
throw new Error("expected model lookup to fail")
|
||||
} catch (e) {
|
||||
if (!Provider.ModelNotFoundError.isInstance(e)) throw e
|
||||
expect(e.data.suggestions).toContain("claude-haiku-4-5")
|
||||
expect(e.suggestions).toContain("claude-haiku-4-5")
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user