|
1 | 1 | import type { FastMCP } from "fastmcp"; |
2 | 2 | import { z } from "zod"; |
3 | 3 | 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"; |
6 | 6 | import { FormatSchema } from "./schemas.js"; |
7 | 7 |
|
8 | 8 | // --------------------------------------------------------------------------- |
@@ -120,22 +120,22 @@ export function registerModulePinHintTool(server: FastMCP): void { |
120 | 120 | const ref = args.ref; |
121 | 121 |
|
122 | 122 | 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 | + ); |
128 | 128 | } |
129 | 129 |
|
130 | 130 | try { |
131 | 131 | const commit = await resolveCommit(owner, repo, ref); |
132 | 132 | 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 | + ); |
139 | 139 | } |
140 | 140 |
|
141 | 141 | const goPseudoVersion = buildGoPseudoVersion(commit.committedDate, commit.oid); |
@@ -171,9 +171,8 @@ export function registerModulePinHintTool(server: FastMCP): void { |
171 | 171 | ]; |
172 | 172 |
|
173 | 173 | 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)); |
177 | 176 | } |
178 | 177 | }, |
179 | 178 | }); |
|
0 commit comments