Skip to content

Commit 4489423

Browse files
committed
refactor(module-pin-hint): migrate tool errors to envelope
- unsupported_language -> UNSUPPORTED_LANGUAGE with suggestedFix - missing ref -> NOT_FOUND (replaces {error:'not_found',ref:...}) - query_failed catch -> classifyError BREAKING: top-level failures now emit {"error":{code,message,retryable,suggestedFix?}} and drop the structured owner/repo/ref echo.
1 parent 5900829 commit 4489423

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/server/module-pin-hint-tool.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { FastMCP } from "fastmcp";
22
import { z } from "zod";
33
import { gateAuth } from "./github-auth.js";
4-
import { graphqlQuery } from "./github-client.js";
5-
import { errorRespond, jsonRespond } from "./json.js";
4+
import { classifyError, graphqlQuery } from "./github-client.js";
5+
import { errorRespond, jsonRespond, mkError } from "./json.js";
66
import { FormatSchema } from "./schemas.js";
77

88
// ---------------------------------------------------------------------------
@@ -120,22 +120,22 @@ export function registerModulePinHintTool(server: FastMCP): void {
120120
const ref = args.ref;
121121

122122
if (language !== "go") {
123-
return jsonRespond({
124-
error: "unsupported_language",
125-
language,
126-
hint: "Only 'go' is supported in the current version.",
127-
});
123+
return errorRespond(
124+
mkError("UNSUPPORTED_LANGUAGE", `Language '${language}' is not supported.`, {
125+
suggestedFix: "Only 'go' is supported in the current version.",
126+
}),
127+
);
128128
}
129129

130130
try {
131131
const commit = await resolveCommit(owner, repo, ref);
132132
if (!commit) {
133-
return jsonRespond({
134-
error: "not_found",
135-
owner,
136-
repo,
137-
ref: ref ?? "(default branch)",
138-
});
133+
return errorRespond(
134+
mkError(
135+
"NOT_FOUND",
136+
`Ref '${ref ?? "(default branch)"}' not found in ${owner}/${repo}.`,
137+
),
138+
);
139139
}
140140

141141
const goPseudoVersion = buildGoPseudoVersion(commit.committedDate, commit.oid);
@@ -171,9 +171,8 @@ export function registerModulePinHintTool(server: FastMCP): void {
171171
];
172172

173173
return lines.join("\n");
174-
} catch (e) {
175-
const msg = e instanceof Error ? e.message : String(e);
176-
return jsonRespond({ error: "query_failed", owner, repo, message: msg });
174+
} catch (err) {
175+
return errorRespond(classifyError(err));
177176
}
178177
},
179178
});

0 commit comments

Comments
 (0)