Skip to content

Commit 4f9e41a

Browse files
authored
Merge #4246 ci: fail on "rejected promise not handled"
2 parents f126a56 + 686adf0 commit 4f9e41a

File tree

14 files changed

+69
-31
lines changed

14 files changed

+69
-31
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ To run a single test in VSCode, do any one of:
176176
177177
- Unix/macOS/POSIX shell:
178178
```
179-
TEST_FILE=src/test/foo.test npm run test
179+
TEST_FILE=src/test/foo.test.ts npm run test
180180
```
181181
- Powershell:
182182
```
183-
$Env:TEST_FILE = "src/test/foo.test"; npm run test
183+
$Env:TEST_FILE = "src/test/foo.test.ts"; npm run test
184184
```
185185
186186
- To run all tests in a particular subdirectory, you can edit

buildspec/linuxTests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ phases:
3636
# Ensure that "foo | run_and_report" fails correctly.
3737
set -o pipefail
3838
. buildspec/shared/common.sh
39-
2>&1 xvfb-run npm test --silent | run_and_report \
39+
2>&1 xvfb-run npm test --silent | run_and_report 2 \
4040
'rejected promise not handled' \
4141
'This typically indicates a bug. Read https://developer.mozilla.org/docs/Web/JavaScript/Guide/Using_promises#error_handling'
4242
}

buildspec/shared/common.sh

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,48 @@
1+
#!/bin/env bash
2+
13
# Common functions used by other CI scripts.
24
# "Include" this file by sourcing (not executing) it:
35
# . buildspec/shared/common.sh
46

7+
# Ignore these patterns when deciding if the build should fail.
8+
# - "waiting for browser": from `ssoAccessTokenProvider.test.ts`, unclear how to fix it.
9+
# - "Webview is disposed": only happens on vscode "minimum" (1.68.0)
10+
# - "HTTPError: Response code …": caused by github rate-limiting.
11+
_ignore_pat='Timed-out waiting for browser login flow\|HTTPError: Response code 403\|HTTPError: Response code 404'
12+
if [ "$VSCODE_TEST_VERSION" = 'minimum' ]; then
13+
_ignore_pat="$_ignore_pat"'\|Webview is disposed'
14+
fi
15+
516
# Expects stdin + two args:
6-
# 1: grep pattern
7-
# 2: message shown at end of report, if pattern was found in stdin.
17+
# 1: error code to return on failure
18+
# 2: grep pattern
19+
# 3: message shown at end of report, if pattern was found in stdin.
820
# Usage:
9-
# echo foo | run_and_report '.*' 'You must fix this. See https://example.com'
21+
# echo foo | run_and_report 1 '.*' 'You must fix this. See https://example.com'
1022
run_and_report() {
1123
set -o pipefail
12-
local pat="${1}"
13-
local msg="${2}"
24+
local errcode="${1}"
25+
local pat="${2}"
26+
local msg="${3}"
1427
local r=0
1528
mkfifo testout
1629
(cat testout &)
1730
# Capture messages that we may want to fail (or report) later.
1831
tee testout \
1932
| { grep > testout-err --line-buffered -E "$pat" || true; }
33+
2034
echo ''
21-
if grep "$pat" testout-err | sort; then
22-
printf '\nERROR: Found %s "%s" in test output (see above).\n%s\n\n' \
23-
"$(grep "${pat}" testout-err | wc -l | tr -d ' ')" \
35+
36+
if grep -v "${_ignore_pat}" testout-err | grep "$pat" | sort; then
37+
printf '\nERROR: Test output matched this pattern %s times:\n "%s"\n%s\n\n' \
38+
"$(grep -c "${pat}" testout-err)" \
2439
"$pat" \
2540
" ${msg}"
26-
# TODO: fail the CI job
27-
# r=1
28-
r=0
41+
r=${errcode}
42+
else
43+
printf '\nOK: Not found in test output: "%s"\n' "$pat"
2944
fi
45+
3046
rm -f testout testout-err
3147
return "$r"
3248
}

buildspec/shared/linux-pre_build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ if [ "$TOOLKITS_CODEARTIFACT_DOMAIN" ] && [ "$TOOLKITS_CODEARTIFACT_REPO" ] && [
2222
fi
2323

2424
# TODO: move this to the "install" phase?
25-
npm 2>&1 ci | run_and_report 'npm WARN deprecated' 'Deprecated dependencies must be updated.'
25+
# TODO: fail in CI
26+
npm 2>&1 ci | run_and_report 0 'npm WARN deprecated' 'Deprecated dependencies must be updated.'

src/auth/connection.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ export async function* loadLinkedProfilesIntoStore(
300300

301301
const stream = client
302302
.listAccounts()
303+
.catch(e => {
304+
getLogger().error('listAccounts() failed: %s', (e as Error).message)
305+
return []
306+
})
303307
.flatten()
304308
.map(resp => {
305309
accounts.add(resp.accountId)

src/codewhisperer/commands/basicCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export const showTransformByQ = Commands.declare(
135135
passive: false,
136136
})
137137
}
138-
await vscode.commands.executeCommand('aws.codeWhisperer.refresh')
138+
await Commands.tryExecute('aws.codeWhisperer.refresh')
139139
}
140140
)
141141

src/codewhisperer/util/authUtil.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ export class AuthUtil {
9393
return
9494
}
9595
this._isCustomizationFeatureEnabled = value
96-
void vscode.commands.executeCommand('aws.codeWhisperer.refresh')
96+
void Commands.tryExecute('aws.codeWhisperer.refresh')
9797
void Commands.tryExecute('aws.amazonq.refresh')
98-
void vscode.commands.executeCommand('aws.codeWhisperer.refreshStatusBar')
98+
void Commands.tryExecute('aws.codeWhisperer.refreshStatusBar')
9999
}
100100

101101
public readonly secondaryAuth = getSecondaryAuth(
@@ -332,11 +332,11 @@ export class AuthUtil {
332332

333333
public async refreshCodeWhisperer() {
334334
await Promise.all([
335-
vscode.commands.executeCommand('aws.codeWhisperer.refresh'),
336-
vscode.commands.executeCommand('aws.codeWhisperer.refreshRootNode'),
335+
Commands.tryExecute('aws.codeWhisperer.refresh'),
336+
Commands.tryExecute('aws.codeWhisperer.refreshRootNode'),
337337
Commands.tryExecute('aws.amazonq.refresh'),
338-
vscode.commands.executeCommand('aws.amazonq.refreshRootNode'),
339-
vscode.commands.executeCommand('aws.codeWhisperer.refreshStatusBar'),
338+
Commands.tryExecute('aws.amazonq.refreshRootNode'),
339+
Commands.tryExecute('aws.codeWhisperer.refreshStatusBar'),
340340
])
341341
}
342342

src/codewhisperer/util/customizationUtil.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { codicon, getIcon } from '../../shared/icons'
2323
import { getLogger } from '../../shared/logger'
2424
import { showMessageWithUrl } from '../../shared/utilities/messages'
2525
import { parse } from '@aws-sdk/util-arn-parser'
26+
import { Commands } from '../../shared/vscode/commands2'
2627

2728
/**
2829
*
@@ -118,8 +119,8 @@ export const setSelectedCustomization = async (customization: Customization) =>
118119
getLogger().debug(`Selected customization ${customization.name} for ${AuthUtil.instance.conn.label}`)
119120

120121
await set(selectedCustomizationKey, selectedCustomizationObj, globals.context.globalState)
121-
await vscode.commands.executeCommand('aws.codeWhisperer.refresh')
122-
await vscode.commands.executeCommand('aws.codeWhisperer.refreshStatusBar')
122+
await Commands.tryExecute('aws.codeWhisperer.refresh')
123+
await Commands.tryExecute('aws.codeWhisperer.refreshStatusBar')
123124
}
124125

125126
export const getPersistedCustomizations = (): Customization[] => {
@@ -147,7 +148,7 @@ export const getNewCustomizationAvailable = () => {
147148

148149
export const setNewCustomizationAvailable = async (available: boolean) => {
149150
await set(newCustomizationAvailableKey, available, globals.context.globalState)
150-
await vscode.commands.executeCommand('aws.codeWhisperer.refresh')
151+
await Commands.tryExecute('aws.codeWhisperer.refresh')
151152
}
152153

153154
export async function showCustomizationPrompt() {

src/codewhisperer/util/getStartUrl.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import * as vscode from 'vscode'
76
import * as CodeWhispererConstants from '../models/constants'
87
import { isValidResponse } from '../../shared/wizards/wizard'
98
import { AuthUtil, amazonQScopes } from './authUtil'
@@ -35,7 +34,7 @@ export async function connectToEnterpriseSso(startUrl: string, region: Region['i
3534
code: 'FailedToConnect',
3635
})
3736
}
38-
await vscode.commands.executeCommand('aws.codeWhisperer.refresh')
37+
await Commands.tryExecute('aws.codeWhisperer.refresh')
3938
await Commands.tryExecute('aws.amazonq.refresh')
40-
await vscode.commands.executeCommand('aws.codeWhisperer.enableCodeSuggestions')
39+
await Commands.tryExecute('aws.codeWhisperer.enableCodeSuggestions')
4140
}

src/codewhisperer/util/showSsoPrompt.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export async function awsIdSignIn() {
5252
} catch (e) {
5353
throw ToolkitError.chain(e, failedToConnectAwsBuilderId, { code: 'FailedToConnect' })
5454
}
55-
await vscode.commands.executeCommand('aws.codeWhisperer.refresh')
55+
await Commands.tryExecute('aws.codeWhisperer.refresh')
5656
await Commands.tryExecute('aws.amazonq.refresh')
57-
await vscode.commands.executeCommand('aws.codeWhisperer.enableCodeSuggestions')
57+
await Commands.tryExecute('aws.codeWhisperer.enableCodeSuggestions')
5858
}
5959

6060
export const createCodeWhispererIamItem = () => {

0 commit comments

Comments
 (0)