Skip to content

Commit

Permalink
fix(codewhisperer): "TypeError: Cannot read properties of undefined" #…
Browse files Browse the repository at this point in the history
…4210

Problem:
CI test logs are showing many of these unhandled rejections:

    rejected promise not handled within 1 second: TypeError: Cannot read properties of undefined (reading 'range')
    stack trace: TypeError: Cannot read properties of undefined (reading 'range')
        at SecurityIssueHoverProvider.handleDocumentChange (/codebuild/output/src3775465363/src/github.com/aws/aws-toolkit-vscode/src/codewhisperer/service/securityIssueProvider.ts:20:54)
        at f.value (/codebuild/output/src3775465363/src/github.com/aws/aws-toolkit-vscode/src/codewhisperer/activation.ts:331:53)

Solution:
Skip `handleDocumentChange` if the event looks invalid. The event may be
triggered by edits from our own "code generation" logic, which presumably is
causing some weird behavior.

Fix #4203
  • Loading branch information
laileni-aws authored Jan 4, 2024
1 parent 2ca4fde commit 4bdcca3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/codewhisperer/service/securityIssueProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import * as vscode from 'vscode'
import { AggregatedCodeScanIssue } from '../models/model'

export abstract class SecurityIssueProvider {
private _issues: AggregatedCodeScanIssue[] = []
public get issues() {
Expand All @@ -17,6 +16,10 @@ export abstract class SecurityIssueProvider {
}

public handleDocumentChange(event: vscode.TextDocumentChangeEvent) {
// handleDocumentChange function may be triggered while testing by our own code generation.
if (!event.contentChanges || event.contentChanges.length === 0) {
return
}
const changedRange = event.contentChanges[0].range
const changedText = event.contentChanges[0].text
const lineOffset = this._getLineOffset(changedRange, changedText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ export class cloudformationDependencyGraph extends DependencyGraph {
}
}

export class CsharpDependencyGraphError extends Error {}
export class cloudformationDependencyGraphError extends Error {}

0 comments on commit 4bdcca3

Please sign in to comment.