Skip to content

Commit

Permalink
Merge aws#4239 require "await" or .catch() on async calls
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmk3 authored Jan 8, 2024
2 parents 478e1be + 65e65fc commit 4558d3b
Show file tree
Hide file tree
Showing 61 changed files with 242 additions and 194 deletions.
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ async function checkSettingsHealth(settings: Settings): Promise<boolean> {
const openSettingsItem = 'Open settings.json'
void showViewLogsMessage(msg, 'error', [openSettingsItem]).then(async resp => {
if (resp === openSettingsItem) {
vscode.commands.executeCommand('workbench.action.openSettingsJson')
await vscode.commands.executeCommand('workbench.action.openSettingsJson')
}
})
return false
Expand Down
2 changes: 1 addition & 1 deletion src/iot/commands/deleteCert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export async function deleteCertCommand(node: IotCertWithPoliciesNode): Promise<
}
} catch (e) {
getLogger().error(`Failed to retrieve Policies attached to cert ${node.certificate.id}: %s`, e)
showViewLogsMessage(
void showViewLogsMessage(
localize('AWS.iot.deleteCert.retrieveError', 'Failed to retrieve {0} attached to certificate', 'policies')
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/iot/commands/deletePolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function deletePolicyCommand(node: IotPolicyWithVersionsNode): Prom
}
if (numVersions !== 1) {
getLogger().error(`Policy ${policyName} has non-default versions`)
vscode.window.showErrorMessage(
void vscode.window.showErrorMessage(
localize('AWS.iot.deletePolicy.versionError', 'Policy {0} has non-default versions', policyName)
)
return
Expand Down
2 changes: 1 addition & 1 deletion src/iot/commands/deletePolicyVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function deletePolicyVersionCommand(node: IotPolicyVersionNode): Pr
await node.iot.deletePolicyVersion({ policyName, policyVersionId })

getLogger().info(`deleted Policy Version: ${policyVersionId}`)
vscode.window.showInformationMessage(
void vscode.window.showInformationMessage(
localize(
'AWS.iot.deletePolicyVersion.success',
'Deleted Version {0} of Policy {1}',
Expand Down
2 changes: 1 addition & 1 deletion src/lambda/commands/createNewSamApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export async function createNewSamApplication(

await schemaCodeDownloader!.downloadCode(request!)

vscode.window.showInformationMessage(
void vscode.window.showInformationMessage(
localize(
'AWS.message.info.schemas.downloadCodeBindings.finished',
'Downloaded code for schema {0}!',
Expand Down
4 changes: 2 additions & 2 deletions src/lambda/local/debugConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export async function getHandlerName(
}
default: {
// Should never happen.
vscode.window.showErrorMessage(
void vscode.window.showErrorMessage(
localize(
'AWS.sam.debugger.invalidTarget',
'Debug Configuration has an unsupported target type. Supported types: {0}',
Expand Down Expand Up @@ -257,7 +257,7 @@ export function getArchitecture(

if (!isArch) {
getLogger('channel').warn('SAM Invoke: Invalid architecture. Defaulting to x86_64.')
vscode.window.showWarningMessage(
void vscode.window.showWarningMessage(
localize(
'AWS.output.sam.invalidArchitecture',
'Invalid architecture specified in {0}. Defaulting to x86_64 architecture for invocation.',
Expand Down
4 changes: 2 additions & 2 deletions src/lambda/models/samLambdaRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function getFamily(runtime: string): RuntimeFamily {

function handleDeprecatedRuntime(runtime: Runtime) {
const moreInfo = localize('AWS.generic.message.learnMore', 'Learn More')
vscode.window
void vscode.window
.showErrorMessage(
localize(
'AWS.samcli.deprecatedRuntime',
Expand All @@ -166,7 +166,7 @@ function handleDeprecatedRuntime(runtime: Runtime) {
)
.then(button => {
if (button === moreInfo) {
openUrl(vscode.Uri.parse(supportedLambdaRuntimesUrl))
void openUrl(vscode.Uri.parse(supportedLambdaRuntimesUrl))
}
})
throw new Error(`Runtime ${runtime} is deprecated, see: ${supportedLambdaRuntimesUrl}`)
Expand Down
24 changes: 15 additions & 9 deletions src/lambda/vue/configEditor/samInvokeBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class SamInvokeWebview extends VueWebview {
? vscode.workspace.workspaceFolders[0]
: undefined
if (!workspaceFolder) {
vscode.window.showErrorMessage(localize('AWS.lambda.form.noFolder', 'No workspace folder found.'))
void vscode.window.showErrorMessage(localize('AWS.lambda.form.noFolder', 'No workspace folder found.'))
return
}
const uri = workspaceFolder.uri
Expand Down Expand Up @@ -223,7 +223,9 @@ export class SamInvokeWebview extends VueWebview {
const uri = getUriFromLaunchConfig(config)
if (!uri) {
// TODO Localize
vscode.window.showErrorMessage('Toolkit requires a target resource in order to save a debug configuration')
void vscode.window.showErrorMessage(
'Toolkit requires a target resource in order to save a debug configuration'
)
return
}
const launchConfig = new LaunchConfiguration(uri)
Expand Down Expand Up @@ -264,12 +266,15 @@ export class SamInvokeWebview extends VueWebview {
})
const response = await input.promptUser({ inputBox: ib })
if (response) {
launchConfig.addDebugConfiguration(finalizeConfig(config, response))
await launchConfig.addDebugConfiguration(finalizeConfig(config, response))
await openLaunchJsonFile()
}
} else {
// use existing label
launchConfig.editDebugConfiguration(finalizeConfig(config, pickerResponse.label), pickerResponse.index)
await launchConfig.editDebugConfiguration(
finalizeConfig(config, pickerResponse.label),
pickerResponse.index
)
await openLaunchJsonFile()
}
}
Expand Down Expand Up @@ -306,12 +311,13 @@ const WebviewPanel = VueWebview.compilePanel(SamInvokeWebview)
export function registerSamInvokeVueCommand(context: ExtContext): vscode.Disposable {
return Commands.register('aws.launchConfigForm', async (launchConfig?: AwsSamDebuggerConfiguration) => {
const webview = new WebviewPanel(context.extensionContext, context, launchConfig)
webview.show({
title: localize('AWS.command.launchConfigForm.title', 'Edit SAM Debug Configuration'),
// TODO: make this only open `Beside` when executed via CodeLens
viewColumn: vscode.ViewColumn.Beside,
await telemetry.sam_openConfigUi.run(async span => {
await webview.show({
title: localize('AWS.command.launchConfigForm.title', 'Edit SAM Debug Configuration'),
// TODO: make this only open `Beside` when executed via CodeLens
viewColumn: vscode.ViewColumn.Beside,
})
})
telemetry.sam_openConfigUi.emit()
})
}

Expand Down
54 changes: 40 additions & 14 deletions src/lambda/vue/configEditor/samInvokeFrontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,30 @@ export default defineComponent({
settingsPanel,
},
created() {
client.init().then(config => this.parseConfig(config))
client.init().then(
config => this.parseConfig(config),
e => {
console.error('client.init failed: %s', (e as Error).message)
}
)

client.getRuntimes().then(runtimes => {
this.runtimes = runtimes
})
client.getRuntimes().then(
runtimes => {
this.runtimes = runtimes
},
e => {
console.error('client.getRuntimes failed: %s', (e as Error).message)
}
)

client.getCompanyName().then(o => {
this.company = o
})
client.getCompanyName().then(
o => {
this.company = o
},
e => {
console.error('client.getCompanyName failed: %s', (e as Error).message)
}
)
},
mixins: [saveData],
data(): SamInvokeVueData {
Expand All @@ -145,11 +160,17 @@ export default defineComponent({
},
launch() {
const config = this.formatConfig()
config && client.invokeLaunchConfig(config)
config &&
client.invokeLaunchConfig(config).catch(e => {
console.error('invokeLaunchConfig failed: %s', (e as Error).message)
})
},
save() {
const config = this.formatConfig()
config && client.saveLaunchConfig(config)
config &&
client.saveLaunchConfig(config).catch(e => {
console.error('saveLaunchConfig failed: %s', (e as Error).message)
})
},
loadConfig() {
client.loadSamLaunchConfig().then(config => this.parseConfig(config))
Expand Down Expand Up @@ -183,12 +204,17 @@ export default defineComponent({
},
loadPayload() {
this.resetJsonErrors()
client.getSamplePayload().then(sample => {
if (!sample) {
return
client.getSamplePayload().then(
sample => {
if (!sample) {
return
}
this.payload.value = JSON.stringify(JSON.parse(sample), undefined, 4)
},
e => {
console.error('client.getSamplePayload failed: %s', (e as Error).message)
}
this.payload.value = JSON.stringify(JSON.parse(sample), undefined, 4)
})
)
},
loadResource() {
this.resetJsonErrors()
Expand Down
2 changes: 1 addition & 1 deletion src/lambda/vue/remoteInvoke/invokeLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class RemoteInvokeWebview extends VueWebview {
}
} catch (e) {
getLogger().error('readFileSync: Failed to read file at path %O', fileLocations[0].fsPath, e)
vscode.window.showErrorMessage((e as Error).message)
void vscode.window.showErrorMessage((e as Error).message)
}
}
}
Expand Down
28 changes: 16 additions & 12 deletions src/lambda/wizards/samDeployWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
if (button === vscode.QuickInputButtons.Back) {
resolve(undefined)
} else if (button === this.helpButton) {
openUrl(vscode.Uri.parse(samDeployDocUrl))
void openUrl(vscode.Uri.parse(samDeployDocUrl))
}
},
})
Expand Down Expand Up @@ -292,7 +292,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
if (button === vscode.QuickInputButtons.Back) {
resolve(undefined)
} else if (button === this.helpButton) {
openUrl(vscode.Uri.parse(samDeployDocUrl))
void openUrl(vscode.Uri.parse(samDeployDocUrl))
}
},
})
Expand Down Expand Up @@ -336,7 +336,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
if (button === vscode.QuickInputButtons.Back) {
resolve(undefined)
} else if (button === this.helpButton) {
openUrl(vscode.Uri.parse(samDeployDocUrl))
void openUrl(vscode.Uri.parse(samDeployDocUrl))
}
},
})
Expand Down Expand Up @@ -385,7 +385,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
if (button === vscode.QuickInputButtons.Back) {
resolve(undefined)
} else if (button === this.helpButton) {
openUrl(vscode.Uri.parse(samDeployDocUrl))
void openUrl(vscode.Uri.parse(samDeployDocUrl))
}
},
})
Expand Down Expand Up @@ -447,15 +447,19 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
// This will background load the S3 buckets and load them all (in one chunk) when the operation completes.
// Not awaiting lets us display a "loading" quick pick for immediate feedback.
// Does not use an IteratingQuickPick because listing S3 buckets by region is not a paginated operation.
populateS3QuickPick(quickPick, selectedRegion, SamCliSettings.instance, messages, profile, accountId)
populateS3QuickPick(quickPick, selectedRegion, SamCliSettings.instance, messages, profile, accountId).catch(
e => {
getLogger().error('populateS3QuickPick: %s', (e as Error).message)
}
)

const choices = await picker.promptUser<vscode.QuickPickItem>({
picker: quickPick,
onDidTriggerButton: (button, resolve, reject) => {
if (button === vscode.QuickInputButtons.Back) {
resolve(undefined)
} else if (button === this.helpButton) {
openUrl(vscode.Uri.parse(samDeployDocUrl))
void openUrl(vscode.Uri.parse(samDeployDocUrl))
} else if (button === createBucket) {
resolve([{ label: CREATE_NEW_BUCKET }])
} else if (button === enterBucket) {
Expand Down Expand Up @@ -511,7 +515,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
if (button === vscode.QuickInputButtons.Back) {
resolve(undefined)
} else if (button === this.helpButton) {
openUrl(vscode.Uri.parse(samDeployDocUrl))
void openUrl(vscode.Uri.parse(samDeployDocUrl))
} else if (bucketProps.buttonHandler) {
bucketProps.buttonHandler(button, inputBox, resolve, reject)
}
Expand Down Expand Up @@ -555,7 +559,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
if (button === vscode.QuickInputButtons.Back) {
resolve(undefined)
} else if (button === this.helpButton) {
openUrl(vscode.Uri.parse(samDeployDocUrl))
void openUrl(vscode.Uri.parse(samDeployDocUrl))
}
},
})
Expand Down Expand Up @@ -608,7 +612,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
if (button === vscode.QuickInputButtons.Back) {
resolve(undefined)
} else if (button === this.helpButton) {
openUrl(vscode.Uri.parse(samDeployDocUrl))
void openUrl(vscode.Uri.parse(samDeployDocUrl))
}
},
})
Expand Down Expand Up @@ -710,7 +714,7 @@ export class SamDeployWizard extends MultiStepWizard<SamDeployWizardResponse> {
// TODO: remove check when min version is high enough
const samCliVersion = await getSamCliVersion(this.context.extContext.samCliContext())
if (semver.lt(samCliVersion, minSamCliVersionForImageSupport)) {
vscode.window.showErrorMessage(
void vscode.window.showErrorMessage(
localize(
'AWS.output.sam.no.image.support',
'Support for Image-based Lambdas requires a minimum SAM CLI version of 1.13.0.'
Expand Down Expand Up @@ -800,12 +804,12 @@ export class SamDeployWizard extends MultiStepWizard<SamDeployWizardResponse> {
const newBucketName = (await s3Client.createBucket({ bucketName: newBucketRequest })).bucket.name
this.response.s3Bucket = newBucketName
getLogger().info('Created bucket: %O', newBucketName)
vscode.window.showInformationMessage(
void vscode.window.showInformationMessage(
localize('AWS.s3.createBucket.success', 'Created bucket: {0}', newBucketName)
)
telemetry.s3_createBucket.emit({ result: 'Succeeded' })
} catch (e) {
showViewLogsMessage(
void showViewLogsMessage(
localize('AWS.s3.createBucket.error.general', 'Failed to create bucket: {0}', newBucketRequest)
)
telemetry.s3_createBucket.emit({ result: 'Failed' })
Expand Down
6 changes: 3 additions & 3 deletions src/lambda/wizards/samInitWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function createRegistryPrompter(region: string, credentials?: AWS.Credentials):
.getRegistries(region, client, credentials!)
.then(registryNames => {
if (!registryNames) {
vscode.window.showInformationMessage(
void vscode.window.showInformationMessage(
localize(
'AWS.samcli.initWizard.schemas.registry.failed_to_load_resources',
'Error loading registries.'
Expand Down Expand Up @@ -131,7 +131,7 @@ function createSchemaPrompter(
.getSchemas(region, registry, client, credentials!)
.then(schemas => {
if (!schemas) {
vscode.window.showInformationMessage(
void vscode.window.showInformationMessage(
localize(
'AWS.samcli.initWizard.schemas.failed_to_load_resources',
'Error loading schemas in registry {0}.',
Expand All @@ -142,7 +142,7 @@ function createSchemaPrompter(
}

if (schemas.length === 0) {
vscode.window.showInformationMessage(
void vscode.window.showInformationMessage(
localize('AWS.samcli.initWizard.schemas.notFound"', 'No schemas found in registry {0}.', registry)
)
return []
Expand Down
4 changes: 3 additions & 1 deletion src/redshift/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ function getCreateNotebookClickedHandler(redshiftNotebookController: RedshiftNot
redshiftNotebookController.redshiftClient = new DefaultRedshiftClient(region)
} catch (e) {
const err = e as Error
showViewLogsMessage(localize('AWS.command.notebook.fail', 'Failed to create notebook: {0}', err.message))
void showViewLogsMessage(
localize('AWS.command.notebook.fail', 'Failed to create notebook: {0}', err.message)
)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/redshift/messageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ export function createLogsConnectionMessage(warehouseIdentifier: string, error:
export function showViewLogsFetchMessage(fetchType: string, identifier: string, error: Error) {
const message = `Redshift: failed to fetch ${fetchType} for ${identifier}: ${(error as Error).message}`
getLogger().error(message)
showViewLogsMessage(message)
void showViewLogsMessage(message)
}
Loading

0 comments on commit 4558d3b

Please sign in to comment.