Skip to content

Commit 73e0812

Browse files
committed
Redirect view logs action to open the terminal instead of output channel
1 parent db097d0 commit 73e0812

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

packages/core/src/shared/sam/build.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ import globals from '../extensionGlobals'
1919
import { TreeNode } from '../treeview/resourceTreeDataProvider'
2020
import { telemetry } from '../telemetry/telemetry'
2121
import { getSpawnEnv } from '../env/resolveEnv'
22-
import { getErrorCode, getProjectRoot, getSamCliPathAndVersion, isDotnetRuntime, updateRecentResponse } from './utils'
22+
import {
23+
getErrorCode,
24+
getProjectRoot,
25+
getSamCliPathAndVersion,
26+
getTerminalFromError,
27+
isDotnetRuntime,
28+
updateRecentResponse,
29+
} from './utils'
2330
import { getConfigFileUri, validateSamBuildConfig } from './config'
2431
import { runInTerminal } from './processTerminal'
2532

@@ -240,7 +247,7 @@ export async function runBuild(arg?: TreeNode): Promise<SamBuildResult> {
240247
}
241248
} catch (error) {
242249
throw ToolkitError.chain(error, 'Failed to build SAM template', {
243-
details: { ...resolveBuildArgConflict(buildFlags) },
250+
details: { terminal: getTerminalFromError(error), ...resolveBuildArgConflict(buildFlags) },
244251
code: getErrorCode(error),
245252
})
246253
}

packages/core/src/shared/sam/processTerminal.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ import { throwIfErrorMatches } from './utils'
1616

1717
let oldTerminal: ProcessTerminal | undefined
1818
export async function runInTerminal(proc: ChildProcess, cmd: string) {
19-
const handleResult = (result?: ChildProcessResult) => {
19+
const handleResult = (result?: ChildProcessResult, terminal?: vscode.Terminal) => {
2020
if (result && result.exitCode !== 0) {
2121
throwIfErrorMatches(result)
2222

2323
// If no specific error matched, throw the default non-zero exit code error.
2424
const defaultMessage = `sam ${cmd} exited with a non-zero exit code: ${result.exitCode}`
2525
throw ToolkitError.chain(result.error, defaultMessage, {
2626
code: 'NonZeroExitCode',
27+
details: { terminal: terminal },
2728
})
2829
}
2930
}
@@ -56,7 +57,7 @@ export async function runInTerminal(proc: ChildProcess, cmd: string) {
5657
? ToolkitError.chain(result.error, 'SAM CLI was cancelled before exiting', { cancelled: true })
5758
: new CancellationError('user')
5859
} else {
59-
return handleResult(result)
60+
return handleResult(result, terminal)
6061
}
6162
}
6263

packages/core/src/shared/sam/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ export function throwIfErrorMatches(result: ChildProcessResult) {
132132
}
133133
}
134134

135+
export function getTerminalFromError(error: any): vscode.Terminal {
136+
if (error instanceof ToolkitError) {
137+
error.details?.['terminal'] as unknown as vscode.Terminal
138+
}
139+
140+
return vscode.window.activeTerminal as vscode.Terminal
141+
}
142+
135143
export enum SamCliErrorTypes {
136144
DockerUnreachable = 'Docker is unreachable.',
137145
ResolveS3AndS3Set = 'Cannot use both --resolve-s3 and --s3-bucket parameters in non-guided deployments.',

packages/core/src/shared/utilities/logAndShowUtils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@ export async function logAndShowError(
3232
return
3333
}
3434
const logsItem = localize('AWS.generic.message.viewLogs', 'View Logs...')
35+
const viewInTerminalItem = localize('AWS.generic.message.viewInTerminal', 'View Logs In Terminal')
3536
const logId = getLogger().error(`${topic}: %s`, error)
3637
const message = resolveErrorMessageToDisplay(error, defaultMessage)
3738

3839
if (error instanceof ToolkitError && error.documentationUri) {
3940
await showMessageWithUrl(message, error.documentationUri, 'View Documentation', 'error')
41+
} else if (error instanceof ToolkitError && (error.details?.['terminal'] as unknown as vscode.Terminal)) {
42+
await vscode.window.showErrorMessage(message, viewInTerminalItem).then(async (resp) => {
43+
if (resp === viewInTerminalItem) {
44+
;(error.details?.['terminal'] as unknown as vscode.Terminal).show()
45+
}
46+
})
4047
} else {
4148
await vscode.window.showErrorMessage(message, logsItem).then(async (resp) => {
4249
if (resp === logsItem) {

0 commit comments

Comments
 (0)