Add clarity to error messages (#14879)

This commit is contained in:
Gaurav Sehgal
2025-12-13 06:31:12 +05:30
committed by GitHub
parent ad60cbfc2c
commit d9f94103cd
5 changed files with 88 additions and 54 deletions

View File

@@ -35,7 +35,7 @@ interface HandleAtCommandParams {
interface HandleAtCommandResult {
processedQuery: PartListUnion | null;
shouldProceed: boolean;
error?: string;
}
interface AtCommandPart {
@@ -144,7 +144,7 @@ export async function handleAtCommand({
);
if (atPathCommandParts.length === 0) {
return { processedQuery: [{ text: query }], shouldProceed: true };
return { processedQuery: [{ text: query }] };
}
// Get centralized file discovery service
@@ -172,7 +172,10 @@ export async function handleAtCommand({
{ type: 'error', text: 'Error: read_many_files tool not found.' },
userMessageTimestamp,
);
return { processedQuery: null, shouldProceed: false };
return {
processedQuery: null,
error: 'Error: read_many_files tool not found.',
};
}
for (const atPathPart of atPathCommandParts) {
@@ -189,16 +192,17 @@ export async function handleAtCommand({
if (!pathName) {
// This case should ideally not be hit if parseAllAtCommands ensures content after @
// but as a safeguard:
const errMsg = `Error: Invalid @ command '${originalAtPath}'. No path specified.`;
addItem(
{
type: 'error',
text: `Error: Invalid @ command '${originalAtPath}'. No path specified.`,
text: errMsg,
},
userMessageTimestamp,
);
// Decide if this is a fatal error for the whole command or just skip this @ part
// For now, let's be strict and fail the command if one @path is malformed.
return { processedQuery: null, shouldProceed: false };
return { processedQuery: null, error: errMsg };
}
// Check if this is an MCP resource reference (serverName:uri format)
@@ -417,16 +421,13 @@ export async function handleAtCommand({
onDebugMessage('No valid file paths found in @ commands to read.');
if (initialQueryText === '@' && query.trim() === '@') {
// If the only thing was a lone @, pass original query (which might have spaces)
return { processedQuery: [{ text: query }], shouldProceed: true };
return { processedQuery: [{ text: query }] };
} else if (!initialQueryText && query) {
// If all @-commands were invalid and no surrounding text, pass original query
return { processedQuery: [{ text: query }], shouldProceed: true };
return { processedQuery: [{ text: query }] };
}
// Otherwise, proceed with the (potentially modified) query text that doesn't involve file reading
return {
processedQuery: [{ text: initialQueryText || query }],
shouldProceed: true,
};
return { processedQuery: [{ text: initialQueryText || query }] };
}
const processedQueryParts: PartListUnion = [{ text: initialQueryText }];
@@ -494,7 +495,16 @@ export async function handleAtCommand({
>,
userMessageTimestamp,
);
return { processedQuery: null, shouldProceed: false };
// Find the first error to report
const firstError = resourceReadDisplays.find(
(d) => d.status === ToolCallStatus.Error,
)!;
const errorMessages = resourceReadDisplays
.filter((d) => d.status === ToolCallStatus.Error)
.map((d) => d.resultDisplay);
console.error(errorMessages);
const errorMsg = `Exiting due to an error processing the @ command: ${firstError.resultDisplay}`;
return { processedQuery: null, error: errorMsg };
}
if (pathSpecsToRead.length === 0) {
@@ -507,7 +517,7 @@ export async function handleAtCommand({
userMessageTimestamp,
);
}
return { processedQuery: processedQueryParts, shouldProceed: true };
return { processedQuery: processedQueryParts };
}
const toolArgs = {
@@ -593,7 +603,7 @@ export async function handleAtCommand({
userMessageTimestamp,
);
}
return { processedQuery: processedQueryParts, shouldProceed: true };
return { processedQuery: processedQueryParts };
} catch (error: unknown) {
readManyFilesDisplay = {
callId: `client-read-${userMessageTimestamp}`,
@@ -612,7 +622,10 @@ export async function handleAtCommand({
} as Omit<HistoryItem, 'id'>,
userMessageTimestamp,
);
return { processedQuery: null, shouldProceed: false };
return {
processedQuery: null,
error: `Exiting due to an error processing the @ command: ${readManyFilesDisplay.resultDisplay}`,
};
}
}