Skip to content

Commit d4a5f48

Browse files
authored
fix(logs): improve error logging (#2999)
## Problem * Inconsistent pattern for error logging * Stack traces aren't emitted even when source maps are available * `aws.viewLogsAtMessage` would show an extra error in certain situations ## Solution * Use `%s` for error substitution so the entire object isn't printed * Add logic to map errors in the logs depending on context * Source maps available and we log at error level -> output stack trace * Otherwise format the error in a nicer way * Handle more edge cases in `aws.viewLogsAtMessage`
1 parent e4b96ff commit d4a5f48

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+126
-99
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "logging: `aws.viewLogsAtMessage` no longer fails when the log message cannot be found"
4+
}

src/apigateway/commands/copyUrl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export async function copyUrlCommand(
4747
}
4848
)
4949
} catch (e) {
50-
getLogger().error(`Failed to load stages: %O`, e)
50+
getLogger().error(`Failed to load stages: %s`, e)
5151
telemetry.apigateway_copyUrl.emit({ result: 'Failed' })
5252
return
5353
}

src/apprunner/activation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export async function activate(context: ExtContext): Promise<void> {
8585
try {
8686
await command(...args)
8787
} catch (err) {
88-
getLogger().error(`${tuple[1]}: %O`, err)
88+
getLogger().error(`${tuple[1]}: %s`, err)
8989
showViewLogsMessage(tuple[1])
9090
}
9191
})

src/apprunner/explorer/apprunnerServiceNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class AppRunnerServiceNode extends CloudWatchLogsBase implements AWSResou
127127
getLogger().warn(
128128
`Failed to list operations for service "${this._info.ServiceName}", service may be in an unstable state.`
129129
)
130-
getLogger().debug(`Failed to list operations for service "${this.arn}": %O`, err)
130+
getLogger().debug(`Failed to list operations for service "${this.arn}": %s`, err)
131131
})
132132
}
133133

src/apprunner/wizards/imageRepositoryWizard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function createImagePrompter(
8181
return repos
8282
})
8383
.catch(err => {
84-
getLogger().error(`Unabled to list repositories: %O`, err)
84+
getLogger().error(`Unabled to list repositories: %s`, err)
8585
return [
8686
{
8787
label: localize(
@@ -187,7 +187,7 @@ function createTagPrompter(
187187
return tagT
188188
})
189189
.catch(err => {
190-
getLogger().error(`Unabled to list tags for repository "${imageRepo.repositoryName}": %O`, err)
190+
getLogger().error(`Unabled to list tags for repository "${imageRepo.repositoryName}": %s`, err)
191191
return [
192192
{
193193
label: localize(

src/awsexplorer/awsExplorer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class AwsExplorer implements vscode.TreeDataProvider<AWSTreeNodeBase>, Re
7474
}
7575
} catch (err) {
7676
const error = err as Error
77-
this.logger.error(`Error getting children for node ${element?.label ?? 'Root Node'}: %O`, error)
77+
this.logger.error(`Error getting children for node ${element?.label ?? 'Root Node'}: %s`, error)
7878

7979
childNodes.splice(
8080
0,

src/codewhisperer/activation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const performance = globalThis.performance ?? require('perf_hooks').performance
5353
export async function activate(context: ExtContext): Promise<void> {
5454
// No need to await. This can be removed once the 'hover.enabled' hack is no longer needed.
5555
HoverConfigUtil.instance.restoreHoverConfig().catch(err => {
56-
getLogger().warn('codewhisperer: failed to restore "editor.hover.enabled" setting: %O', err)
56+
getLogger().warn('codewhisperer: failed to restore "editor.hover.enabled" setting: %s', err)
5757
})
5858

5959
const codewhispererSettings = CodeWhispererSettings.instance

src/credentials/auth.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export class Auth implements AuthService, ConnectionManager {
297297
try {
298298
return await this.useConnection({ id })
299299
} catch (err) {
300-
getLogger().warn(`auth: failed to restore previous session: ${UnknownError.cast(err).message}`)
300+
getLogger().warn(`auth: failed to restore previous session: %s`, err)
301301
}
302302
}
303303

@@ -433,7 +433,7 @@ export class Auth implements AuthService, ConnectionManager {
433433
// TODO: this seems to fail on the backend for scoped tokens
434434
await client.logout().catch(err => {
435435
const name = profile.metadata.label ?? id
436-
getLogger().warn(`auth: failed to logout of connection "${name}": ${UnknownError.cast(err)}`)
436+
getLogger().warn(`auth: failed to logout of connection "${name}": %s`, err)
437437
})
438438

439439
return provider.invalidate()
@@ -628,7 +628,7 @@ export class Auth implements AuthService, ConnectionManager {
628628
await this.useConnection({ id })
629629
return true
630630
} catch (err) {
631-
getLogger().warn(`auth: failed to auto-connect using "${id}": ${UnknownError.cast(err).message}`)
631+
getLogger().warn(`auth: failed to auto-connect using "${id}": %s`, err)
632632
return false
633633
}
634634
}

src/credentials/loginManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class LoginManager {
147147
const loginManager = new LoginManager(awsContext, new CredentialsStore())
148148
await loginWithMostRecentCredentials(new CredentialsSettings(), loginManager)
149149
} catch (err) {
150-
getLogger().error('credentials: failed to auto-connect: %O', err)
150+
getLogger().error('credentials: failed to auto-connect: %s', err)
151151
showViewLogsMessage(localize('AWS.credentials.autoconnect.fatal', 'Exception occurred while connecting'))
152152
}
153153
return !!(await awsContext.getCredentials())

src/credentials/secondaryAuth.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { showQuickPick } from '../shared/ui/pickerPrompter'
1111
import { cast, Optional } from '../shared/utilities/typeConstructors'
1212
import { Auth, Connection } from './auth'
1313
import { once } from '../shared/utilities/functionUtils'
14-
import { UnknownError } from '../shared/errors'
1514

1615
async function promptUseNewConnection(newConn: Connection, oldConn: Connection, tools: string[]) {
1716
// Multi-select picker would be better ?
@@ -154,7 +153,7 @@ export class SecondaryAuth<T extends Connection = Connection> {
154153

155154
return this.#savedConnection
156155
} catch (err) {
157-
getLogger().warn(`auth (${this.toolId}): failed to restore connection: ${UnknownError.cast(err).message}`)
156+
getLogger().warn(`auth (${this.toolId}): failed to restore connection: %s`, err)
158157
}
159158
})
160159

0 commit comments

Comments
 (0)