Skip to content

Commit c5f8210

Browse files
seshubawskaranA-aws
authored andcommitted
fix(lambda): AppBuilder messages aws#6362
## Problem Several errors that were being shown to customers did not have enough information for them to take action on the problem. ## Solution Audited all errors and logs shown to customers and updated them to make them more legible and actionable.
1 parent 4d07f18 commit c5f8210

File tree

13 files changed

+59
-50
lines changed

13 files changed

+59
-50
lines changed

packages/core/src/awsService/appBuilder/explorer/detectSamProjects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export async function getFiles(
5757

5858
return await vscode.workspace.findFiles(globPattern, excludePattern)
5959
} catch (error) {
60-
getLogger().error(`Failed to get files with pattern ${pattern}:`, error)
60+
getLogger().error(`Failed to find files with pattern ${pattern}:`, error)
6161
return []
6262
}
6363
}

packages/core/src/awsService/appBuilder/explorer/nodes/appNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class AppNode implements TreeNode {
7373
createPlaceholderItem(
7474
localize(
7575
'AWS.appBuilder.explorerNode.app.noResourceTree',
76-
'[Unable to load Resource tree for this App. Update SAM template]'
76+
'[Unable to load resource tree for this app. Ensure SAM template is correct.]'
7777
)
7878
),
7979
]

packages/core/src/awsService/appBuilder/explorer/nodes/deployedNode.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export async function generateDeployedNode(
9696
.Configuration as Lambda.FunctionConfiguration
9797
newDeployedResource = new LambdaFunctionNode(lambdaNode, regionCode, configuration)
9898
} catch (error: any) {
99-
getLogger().error('Error getting Lambda configuration %O', error)
99+
getLogger().error('Error getting Lambda configuration: %O', error)
100100
throw ToolkitError.chain(error, 'Error getting Lambda configuration', {
101101
code: 'lambdaClientError',
102102
})
@@ -107,7 +107,7 @@ export async function generateDeployedNode(
107107
createPlaceholderItem(
108108
localize(
109109
'AWS.appBuilder.explorerNode.unavailableDeployedResource',
110-
'[Failed to retrive deployed resource.]'
110+
'[Failed to retrive deployed resource. Ensure your AWS account is connected.]'
111111
)
112112
),
113113
]
@@ -119,8 +119,8 @@ export async function generateDeployedNode(
119119
try {
120120
v3configuration = (await v3Client.send(v3command)).Configuration as FunctionConfiguration
121121
logGroupName = v3configuration.LoggingConfig?.LogGroup
122-
} catch {
123-
getLogger().error('Error getting Lambda V3 configuration')
122+
} catch (error: any) {
123+
getLogger().error('Error getting Lambda V3 configuration: %O', error)
124124
}
125125
newDeployedResource.configuration = {
126126
...newDeployedResource.configuration,
@@ -156,7 +156,10 @@ export async function generateDeployedNode(
156156
getLogger().info('Details are missing or are incomplete for: %O', deployedResource)
157157
return [
158158
createPlaceholderItem(
159-
localize('AWS.appBuilder.explorerNode.noApps', '[This resource is not yet supported.]')
159+
localize(
160+
'AWS.appBuilder.explorerNode.noApps',
161+
'[This resource is not yet supported in AppBuilder.]'
162+
)
160163
),
161164
]
162165
}
@@ -166,7 +169,7 @@ export async function generateDeployedNode(
166169
createPlaceholderItem(
167170
localize(
168171
'AWS.appBuilder.explorerNode.unavailableDeployedResource',
169-
'[Failed to retrive deployed resource.]'
172+
'[Failed to retrieve deployed resource. Ensure correct stack name and region are in the samconfig.toml, and that your account is connected.]'
170173
)
171174
),
172175
]

packages/core/src/awsService/appBuilder/explorer/samProject.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@ export async function getStackName(projectRoot: vscode.Uri): Promise<any> {
4242
} catch (error: any) {
4343
switch (error.code) {
4444
case SamConfigErrorCode.samNoConfigFound:
45-
getLogger().info('No stack name or region information available in samconfig.toml: %O', error)
45+
getLogger().info('Stack name and/or region information not found in samconfig.toml: %O', error)
4646
break
4747
case SamConfigErrorCode.samConfigParseError:
48-
getLogger().error(`Error getting stack name or region information: ${error.message}`, error)
48+
getLogger().error(
49+
`Error parsing stack name and/or region information from samconfig.toml: ${error.message}. Ensure the information is correct.`,
50+
error
51+
)
4952
void showViewLogsMessage('Encountered an issue reading samconfig.toml')
5053
break
5154
default:
52-
getLogger().warn(`Error getting stack name or region information: ${error.message}`, error)
55+
getLogger().warn(`Error parsing stack name and/or region information: ${error.message}`, error)
5356
}
5457
return {}
5558
}

packages/core/src/awsService/appBuilder/utils.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ const localize = nls.loadMessageBundle()
2424
export async function runOpenTemplate(arg?: TreeNode) {
2525
const templateUri = arg ? (arg.resource as SamAppLocation).samTemplateUri : await promptUserForTemplate()
2626
if (!templateUri || !(await fs.exists(templateUri))) {
27-
throw new ToolkitError('No template provided', { code: 'NoTemplateProvided' })
27+
throw new ToolkitError('SAM Template not found, cannot open template', { code: 'NoTemplateProvided' })
2828
}
2929
const document = await vscode.workspace.openTextDocument(templateUri)
3030
await vscode.window.showTextDocument(document)
3131
}
3232

3333
/**
34-
* Find and open the lambda handler with given ResoruceNode
34+
* Find and open the lambda handler with given ResourceNode
3535
* If not found, a NoHandlerFound error will be raised
3636
* @param arg ResourceNode
3737
*/
@@ -56,9 +56,12 @@ export async function runOpenHandler(arg: ResourceNode): Promise<void> {
5656
arg.resource.resource.Runtime
5757
)
5858
if (!handlerFile) {
59-
throw new ToolkitError(`No handler file found with name "${arg.resource.resource.Handler}"`, {
60-
code: 'NoHandlerFound',
61-
})
59+
throw new ToolkitError(
60+
`No handler file found with name "${arg.resource.resource.Handler}". Ensure the file exists in the expected location."`,
61+
{
62+
code: 'NoHandlerFound',
63+
}
64+
)
6265
}
6366
await vscode.workspace.openTextDocument(handlerFile).then(async (doc) => await vscode.window.showTextDocument(doc))
6467
}
@@ -90,7 +93,7 @@ export async function getLambdaHandlerFile(
9093
): Promise<vscode.Uri | undefined> {
9194
const family = getFamily(runtime)
9295
if (!supportedRuntimeForHandler.has(family)) {
93-
throw new ToolkitError(`Runtime ${runtime} is not supported for open handler button`, {
96+
throw new ToolkitError(`Runtime ${runtime} is not supported for the 'Open handler' button`, {
9497
code: 'RuntimeNotSupported',
9598
})
9699
}

packages/core/src/awsService/appBuilder/walkthrough.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ export async function getTutorial(
148148
const appSelected = appMap.get(project + runtime)
149149
telemetry.record({ action: project + runtime, source: source ?? 'AppBuilderWalkthrough' })
150150
if (!appSelected) {
151-
throw new ToolkitError(`Tried to get template '${project}+${runtime}', but it hasn't been registered.`)
151+
throw new ToolkitError(`Template '${project}+${runtime}' does not exist, choose another template.`)
152152
}
153153

154154
try {
155155
await getPattern(serverlessLandOwner, serverlessLandRepo, appSelected.asset, outputDir, true)
156156
} catch (error) {
157-
throw new ToolkitError(`Error occurred while fetching the pattern from serverlessland: ${error}`)
157+
throw new ToolkitError(`An error occurred while fetching this pattern from Serverless Land: ${error}`)
158158
}
159159
}
160160

@@ -190,7 +190,7 @@ export async function genWalkthroughProject(
190190
'No'
191191
)
192192
if (choice !== 'Yes') {
193-
throw new ToolkitError(`${defaultTemplateName} already exist`)
193+
throw new ToolkitError(`A file named ${defaultTemplateName} already exists in this path.`)
194194
}
195195
}
196196

@@ -256,9 +256,9 @@ export async function initWalkthroughProjectCommand() {
256256
let runtimeSelected: TutorialRuntimeOptions | undefined = undefined
257257
try {
258258
if (!walkthroughSelected || !(typeof walkthroughSelected === 'string')) {
259-
getLogger().info('exit on no walkthrough selected')
259+
getLogger().info('No walkthrough selected - exiting')
260260
void vscode.window.showErrorMessage(
261-
localize('AWS.toolkit.lambda.walkthroughNotSelected', 'Please select a template first')
261+
localize('AWS.toolkit.lambda.walkthroughNotSelected', 'Select a template in the walkthrough.')
262262
)
263263
return
264264
}
@@ -322,7 +322,7 @@ export async function getOrUpdateOrInstallSAMCli(source: string) {
322322
}
323323
}
324324
} catch (err) {
325-
throw ToolkitError.chain(err, 'Failed to install or detect SAM')
325+
throw ToolkitError.chain(err, 'Failed to install or detect SAM.')
326326
} finally {
327327
telemetry.record({ source: source, toolId: 'sam-cli' })
328328
}

packages/core/src/test/awsService/appBuilder/explorer/detectSamProjects.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('getFiles', () => {
8383

8484
const templateFiles = await getFiles(workspaceFolder, '**/template.{yml,yaml}', '**/.aws-sam/**')
8585
assert.strictEqual(templateFiles.length, 0)
86-
assertLogsContain('Failed to get files with pattern', false, 'error')
86+
assertLogsContain('Failed to find files with pattern', false, 'error')
8787
sandbox.restore()
8888
})
8989
})

packages/core/src/test/awsService/appBuilder/explorer/samProject.test.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('samProject', () => {
4848
assert.strictEqual(region, expectedRegion)
4949
})
5050

51-
it('returns undefined give no stack name or region in samconfig file', async () => {
51+
it('returns undefined given no stack name or region in samconfig file', async () => {
5252
await testFolder.write(
5353
'samconfig.toml',
5454
generateSamconfigData({
@@ -71,24 +71,28 @@ describe('samProject', () => {
7171

7272
const result = await wrapperCall(undefined)
7373
assert.deepStrictEqual(result, {})
74-
assertLogsContain('Error getting stack name or region information: No project folder found', false, 'warn')
74+
assertLogsContain(
75+
'Error parsing stack name and/or region information: No project folder found',
76+
false,
77+
'warn'
78+
)
7579
})
7680

77-
it('returns empty object give no samconfig file found', async () => {
81+
it('returns empty object given no samconfig file found', async () => {
7882
// simulate error when no samconfig.toml file in directory
7983
const result = await getStackName(projectRoot)
8084
assert.deepStrictEqual(result, {})
81-
assertLogsContain('No stack name or region information available in samconfig.toml', false, 'info')
85+
assertLogsContain('Stack name and/or region information not found in samconfig.toml', false, 'info')
8286
})
8387

84-
it('returns empty object give error parsing samconfig file', async () => {
88+
it('returns empty object given error parsing samconfig file', async () => {
8589
// simulate error when parsinf samconfig.toml: missing quote or empty value
8690
await testFolder.write('samconfig.toml', samconfigInvalidData)
8791

8892
const result = await getStackName(projectRoot)
8993
assert.deepStrictEqual(result, {})
9094

91-
assertLogsContain('Error getting stack name or region information:', false, 'error')
95+
assertLogsContain('Error parsing stack name and/or region information from samconfig.toml:', false, 'error')
9296
getTestWindow().getFirstMessage().assertError('Encountered an issue reading samconfig.toml')
9397
})
9498
})
@@ -149,17 +153,6 @@ describe('samProject', () => {
149153
() => getApp(mockSamAppLocation),
150154
new ToolkitError(`Template at ${mockSamAppLocation.samTemplateUri.fsPath} is not valid`)
151155
)
152-
// try {
153-
// await getApp(mockSamAppLocation)
154-
// assert.fail('Test should not reach here. Expect ToolkitError thrown')
155-
// } catch (error) {
156-
// assert(cloudformationTryLoadSpy.calledOnce)
157-
// assert(error instanceof ToolkitError)
158-
// assert.strictEqual(
159-
// error.message,
160-
// `Template at ${mockSamAppLocation.samTemplateUri.fsPath} is not valid`
161-
// )
162-
// }
163156
})
164157
})
165158
})

packages/core/src/test/awsService/appBuilder/utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ describe('AppBuilder Utils', function () {
294294
}
295295
try {
296296
await runOpenTemplate(tNode as TreeNode)
297-
assert.fail('No template provided')
297+
assert.fail('SAM Template not found, cannot open template')
298298
} catch (err) {
299-
assert.strictEqual((err as Error).message, 'No template provided')
299+
assert.strictEqual((err as Error).message, 'SAM Template not found, cannot open template')
300300
}
301301
// Then
302302
assert(openCommand.neverCalledWith(sinon.match.has('fspath', sinon.match(/template.yaml/g))))

packages/core/src/test/awsService/appBuilder/walkthrough.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ describe('AppBuilder Walkthrough', function () {
206206
try {
207207
// When
208208
await genWalkthroughProject('Visual', workspaceUri, undefined)
209-
assert.fail('template.yaml already exist')
209+
assert.fail('A file named template.yaml already exists in this path.')
210210
} catch (e) {
211-
assert.equal((e as Error).message, 'template.yaml already exist')
211+
assert.equal((e as Error).message, 'A file named template.yaml already exists in this path.')
212212
}
213213
// Then
214214
assert.equal(await fs.readFileText(vscode.Uri.joinPath(workspaceUri, 'template.yaml')), prevInfo)
@@ -236,9 +236,9 @@ describe('AppBuilder Walkthrough', function () {
236236
try {
237237
// When
238238
await genWalkthroughProject('S3', workspaceUri, 'python')
239-
assert.fail('template.yaml already exist')
239+
assert.fail('A file named template.yaml already exists in this path.')
240240
} catch (e) {
241-
assert.equal((e as Error).message, 'template.yaml already exist')
241+
assert.equal((e as Error).message, 'A file named template.yaml already exists in this path.')
242242
}
243243
// Then no overwrite happens
244244
assert.equal(await fs.readFileText(vscode.Uri.joinPath(workspaceUri, 'template.yaml')), prevInfo)

0 commit comments

Comments
 (0)