fix: re-throw hub error for non-markdown hub slugs

When hub loading fails for a path that looks like a hub slug (owner/agent)
and is NOT a markdown file, re-throw the hub error instead of showing
"Not a markdown file". This preserves the actual error from the hub
(e.g., network error, auth error, not found) instead of a confusing
generic message.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Nate 2025-12-22 16:45:48 -05:00
parent 53a9fa4cb3
commit f644c8873e
2 changed files with 19 additions and 8 deletions

View file

@ -739,7 +739,9 @@ You are a helpful agent`;
).rejects.toThrow("File not found");
});
it("should throw error for non-markdown paths without trying file fallback", async () => {
it("should re-throw hub error for non-markdown hub slugs", async () => {
// Reset mock to clear any queued values from previous tests
mockLoadPackageFromHub.mockReset();
mockLoadPackageFromHub.mockRejectedValue(new Error("Hub error"));
await expect(
@ -747,7 +749,7 @@ You are a helpful agent`;
).rejects.toThrow("Failed to load agent from owner/agent");
await expect(
agentFileService.getAgentFile("owner/agent"),
).rejects.toThrow("Not a markdown file");
).rejects.toThrow("Hub error");
});
it("should handle permission errors when reading files", async () => {

View file

@ -54,18 +54,27 @@ export class AgentFileService
async getAgentFile(agentPath: string): Promise<AgentFile> {
try {
const isMarkdownPath =
agentPath.endsWith(".md") || agentPath.endsWith(".markdown");
const parts = agentPath.split("/");
if (parts.length === 2 && parts[0] && parts[1] && !parts.includes(".")) {
const looksLikeHubSlug =
parts.length === 2 && parts[0] && parts[1] && !parts.includes(".");
if (looksLikeHubSlug) {
try {
return await loadPackageFromHub(agentPath, agentFileProcessor);
} catch {
// slug COULD be path, fall back to relative path
} catch (hubError) {
// Hub loading failed - only fall back to file if it's a markdown path
if (!isMarkdownPath) {
// Not a markdown path, so re-throw the hub error
throw hubError;
}
// It's a markdown path, fall through to try loading as file
}
}
const isMarkdownPath =
agentPath.endsWith(".md") || agentPath.endsWith(".markdown");
// Only fall back to relative path for markdown files
// Only load from file path for markdown files
if (!isMarkdownPath) {
throw new Error(
`Failed to load agent from ${agentPath}. Not a markdown file`,