Skip to content

Commit b0dbea3

Browse files
committed
fix(skills): report missing ClawHub skills as not found
1 parent 57ebd20 commit b0dbea3

2 files changed

Lines changed: 112 additions & 2 deletions

File tree

‎src/skills/lifecycle/clawhub-install-core.ts‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {
88
normalizeClawHubSha256Integrity,
99
type ClawHubDownloadResult,
1010
} from "../../infra/clawhub-artifacts.js";
11-
import { isDefaultClawHubBaseUrl, resolveClawHubBaseUrl } from "../../infra/clawhub-client.js";
11+
import {
12+
ClawHubRequestError,
13+
isDefaultClawHubBaseUrl,
14+
resolveClawHubBaseUrl,
15+
} from "../../infra/clawhub-client.js";
1216
import {
1317
type ClawHubTrustErrorCode,
1418
ensureClawHubPackageTrustAcknowledged,
@@ -186,6 +190,32 @@ export async function resolveInstallVersion(params: {
186190
return { detail, version };
187191
}
188192

193+
function formatClawHubSkillInstallError(error: unknown, slug: string): string {
194+
if (!(error instanceof ClawHubRequestError)) {
195+
return formatErrorMessage(error);
196+
}
197+
const skillPath = `/api/v1/skills/${encodeURIComponent(slug)}`;
198+
if (
199+
error.status === 404 &&
200+
(error.requestPath.endsWith(skillPath) || error.requestPath.endsWith(`${skillPath}/install`))
201+
) {
202+
return `Skill "${slug}" not found. Run \`openclaw skills list\` to see available skills.`;
203+
}
204+
if (error.status === 401) {
205+
return `ClawHub authentication failed while installing skill "${slug}". Authenticate with ClawHub and try again.`;
206+
}
207+
if (error.status === 403) {
208+
return `ClawHub denied access while installing skill "${slug}". Check your ClawHub access and try again.`;
209+
}
210+
if (error.status === 429) {
211+
return `ClawHub rate limit reached while installing skill "${slug}". Wait and try again later.`;
212+
}
213+
if (error.status >= 500) {
214+
return `ClawHub is temporarily unavailable while installing skill "${slug}". Try again later.`;
215+
}
216+
return `ClawHub could not install skill "${slug}". Check the skill reference and try again.`;
217+
}
218+
189219
function normalizeGitHubSourcePath(raw: string): string {
190220
const parts = raw.replaceAll("\\", "/").split("/").filter(Boolean);
191221
if (parts.length === 0 || parts.some((part) => part === "." || part === "..")) {
@@ -683,6 +713,6 @@ export async function performClawHubSkillInstall(
683713
await archive.cleanup().catch(() => undefined);
684714
}
685715
} catch (err) {
686-
return { ok: false, error: formatErrorMessage(err) };
716+
return { ok: false, error: formatClawHubSkillInstallError(err, params.slug) };
687717
}
688718
}

‎src/skills/lifecycle/clawhub.test.ts‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ vi.mock("../../state/claw-package-adoption.js", () => ({
7979
markClawPackageIndependentlyOwned: markClawPackageIndependentlyOwnedMock,
8080
}));
8181

82+
const { ClawHubRequestError } = await import("../../infra/clawhub-client.js");
83+
8284
const {
8385
installSkillFromClawHub,
8486
preflightSkillFromClawHub,
@@ -354,6 +356,53 @@ describe("skills-clawhub", () => {
354356
});
355357
});
356358

359+
it.each([
360+
{
361+
name: "maps missing install resolutions to the skills-info recovery message",
362+
lookup: "install",
363+
status: 404,
364+
path: "/api/v1/skills/missing-skill/install",
365+
body: "remote not-found detail",
366+
expected:
367+
'Skill "missing-skill" not found. Run `openclaw skills list` to see available skills.',
368+
},
369+
{
370+
name: "maps missing versioned skills to the skills-info recovery message",
371+
lookup: "detail",
372+
status: 404,
373+
path: "/custom-clawhub/api/v1/skills/missing-skill",
374+
body: "remote versioned not-found detail",
375+
expected:
376+
'Skill "missing-skill" not found. Run `openclaw skills list` to see available skills.',
377+
},
378+
{
379+
name: "keeps server failures distinct from missing skills",
380+
lookup: "install",
381+
status: 500,
382+
path: "/api/v1/skills/missing-skill/install",
383+
body: "remote-controlled server failure",
384+
expected:
385+
'ClawHub is temporarily unavailable while installing skill "missing-skill". Try again later.',
386+
},
387+
] as const)("$name", async ({ lookup, status, path: requestPath, body, expected }) => {
388+
const requestError = new ClawHubRequestError({ path: requestPath, status, body });
389+
if (lookup === "detail") {
390+
fetchClawHubSkillDetailMock.mockRejectedValueOnce(requestError);
391+
} else {
392+
fetchClawHubSkillInstallResolutionMock.mockRejectedValueOnce(requestError);
393+
}
394+
395+
const result = await installSkillFromClawHub({
396+
workspaceDir: "/tmp/workspace",
397+
slug: "missing-skill",
398+
...(lookup === "detail" ? { version: "1.2.3" } : {}),
399+
});
400+
401+
expect(result).toEqual({ ok: false, error: expected });
402+
expect(result.ok ? "" : result.error).not.toContain("/api/v1/");
403+
expect(result.ok ? "" : result.error).not.toContain(body);
404+
});
405+
357406
it("installs skills-sh references via a ClawHub-approved pinned GitHub commit", async () => {
358407
const commit = "a".repeat(40);
359408
const reference = "skills-sh:openclaw/skills/weather";
@@ -1887,6 +1936,37 @@ describe("skills-clawhub", () => {
18871936
});
18881937
});
18891938

1939+
it("reports a tracked skill removed from ClawHub with the same recovery message", async () => {
1940+
const workspaceDir = await tempDirs.make("openclaw-missing-update-");
1941+
await writeClawHubOriginFixture({
1942+
workspaceDir,
1943+
slug: "missing-skill",
1944+
installedVersion: "0.9.0",
1945+
});
1946+
const body = "remote update not-found detail";
1947+
fetchClawHubSkillInstallResolutionMock.mockRejectedValueOnce(
1948+
new ClawHubRequestError({
1949+
path: "/clawhub/api/v1/skills/missing-skill/install",
1950+
status: 404,
1951+
body,
1952+
}),
1953+
);
1954+
1955+
const results = await updateSkillsFromClawHub({
1956+
workspaceDir,
1957+
slug: "missing-skill",
1958+
});
1959+
1960+
expect(results).toEqual([
1961+
{
1962+
ok: false,
1963+
error:
1964+
'Skill "missing-skill" not found. Run `openclaw skills list` to see available skills.',
1965+
},
1966+
]);
1967+
expect(results[0]?.ok ? "" : results[0]?.error).not.toContain(body);
1968+
});
1969+
18901970
it("updates official publisher ClawHub skills without fetching security verdicts", async () => {
18911971
const workspaceDir = await tempDirs.make("openclaw-official-owner-update-");
18921972
await writeClawHubOriginFixture({

0 commit comments

Comments
 (0)