Skip to content

Commit 3cdca23

Browse files
Copilotpelikhan
andcommitted
Fix additional variable shadowing and improve error handling
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 48dbcb9 commit 3cdca23

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

cmd/generate/context.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (h *generateCommandHandler) CreateContextFromPrompt() (*PromptPexContext, e
2626
}
2727

2828
runID := fmt.Sprintf("run_%d", time.Now().Unix())
29-
context := &PromptPexContext{
29+
promptContext := &PromptPexContext{
3030
// Unique identifier for the run
3131
RunID: runID,
3232
// The prompt content and metadata
@@ -50,21 +50,21 @@ func (h *generateCommandHandler) CreateContextFromPrompt() (*PromptPexContext, e
5050
} else {
5151
sessionInfo = fmt.Sprintf("reloading session file at %s", *h.sessionFile)
5252
// Check if prompt hashes match
53-
if existingContext.PromptHash != context.PromptHash {
53+
if existingContext.PromptHash != promptContext.PromptHash {
5454
return nil, fmt.Errorf("prompt changed unable to reuse session file")
5555
}
5656

5757
// Merge existing context data
5858
if existingContext != nil {
59-
context = mergeContexts(existingContext, context)
59+
promptContext = mergeContexts(existingContext, promptContext)
6060
}
6161
}
6262
}
6363

64-
h.WriteToParagraph(RenderMessagesToString(context.Prompt.Messages))
64+
h.WriteToParagraph(RenderMessagesToString(promptContext.Prompt.Messages))
6565
h.WriteEndBox(sessionInfo)
6666

67-
return context, nil
67+
return promptContext, nil
6868
}
6969

7070
// loadContextFromFile loads a PromptPexContext from a JSON file

cmd/generate/llm.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ func (h *generateCommandHandler) callModelWithRetry(step string, req azuremodels
6060
if errors.Is(err, context.Canceled) || strings.Contains(err.Error(), "EOF") {
6161
break
6262
}
63-
reader.Close()
63+
if closeErr := reader.Close(); closeErr != nil {
64+
// Log close error but don't override the original error
65+
h.cfg.WriteToOut(fmt.Sprintf("Warning: failed to close reader: %v\n", closeErr))
66+
}
6467
sp.Stop()
6568
return "", err
6669
}

0 commit comments

Comments
 (0)