Skip to content

Commit 2172e21

Browse files
Fix crash when LLM returns no mappings
1 parent 0248276 commit 2172e21

File tree

1 file changed

+20
-0
lines changed
  • workspaces/ballerina/ballerina-extension/src/features/ai/service/datamapper

1 file changed

+20
-0
lines changed

workspaces/ballerina/ballerina-extension/src/features/ai/service/datamapper/datamapper.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ import { URI } from "vscode-uri";
4343
import fs from 'fs';
4444
import { writeBallerinaFileDidOpenTemp } from "../../../../../src/utils/modification";
4545

46+
const NO_MAPPINGS_GENERATED_WARNING = `**No Relevant Mappings Generated**\n\n` +
47+
`The AI was unable to identify compatible field mappings between the input and output structures.\n\n` +
48+
`**Suggestions:**\n` +
49+
`- Check if input and output record structures are correct\n` +
50+
`- Try providing mapping hints or examples\n`;
51+
4652
// =============================================================================
4753
// ENHANCED MAIN ORCHESTRATOR FUNCTION
4854
// =============================================================================
@@ -340,6 +346,13 @@ export async function generateMappingCodeCore(mappingRequest: ProcessMappingPara
340346
attachments: mappingRequest.attachments
341347
}, context, eventHandler);
342348

349+
// Check if no mappings were generated
350+
if (!allMappingsRequest.mappings || allMappingsRequest.mappings.length === 0) {
351+
eventHandler({ type: "content_block", content: NO_MAPPINGS_GENERATED_WARNING });
352+
eventHandler({ type: "stop", command: Command.DataMap });
353+
return;
354+
}
355+
343356
const sourceCodeResponse = await getAllDataMapperSource(allMappingsRequest);
344357

345358
await updateSourceCode({ textEdits: sourceCodeResponse.textEdits, skipPayloadCheck: true });
@@ -694,6 +707,13 @@ export async function generateInlineMappingCodeCore(inlineMappingRequest: Metada
694707
const inlineMappingsResult: InlineMappingsSourceResult =
695708
await generateInlineMappingsSource(inlineMappingRequest, langClient, context, eventHandler);
696709

710+
// Check if no mappings were generated
711+
if (!inlineMappingsResult.allMappingsRequest.mappings || inlineMappingsResult.allMappingsRequest.mappings.length === 0) {
712+
eventHandler({ type: "content_block", content: NO_MAPPINGS_GENERATED_WARNING });
713+
eventHandler({ type: "stop", command: Command.DataMap });
714+
return;
715+
}
716+
697717
await updateSourceCode({ textEdits: inlineMappingsResult.sourceResponse.textEdits, skipPayloadCheck: true });
698718
await new Promise((resolve) => setTimeout(resolve, 100));
699719

0 commit comments

Comments
 (0)