Skip to content

Commit

Permalink
Fix the open log command
Browse files Browse the repository at this point in the history
The command was opening the old log path.
  • Loading branch information
code-asher committed Oct 31, 2024
1 parent 70eb79b commit b0a965f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export class Commands {
*/
public async viewLogs(): Promise<void> {
if (!this.workspaceLogPath) {
vscode.window.showInformationMessage("No logs available.", this.workspaceLogPath || "<unset>")
vscode.window.showInformationMessage("No logs available. Make sure to set coder.proxyLogDirectory to get logs.", this.workspaceLogPath || "<unset>")

Check failure on line 269 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `"No·logs·available.·Make·sure·to·set·coder.proxyLogDirectory·to·get·logs.",·this.workspaceLogPath·||·"<unset>"` with `⏎········"No·logs·available.·Make·sure·to·set·coder.proxyLogDirectory·to·get·logs.",⏎········this.workspaceLogPath·||·"<unset>",⏎······`
return
}
const uri = vscode.Uri.file(this.workspaceLogPath)
Expand Down
28 changes: 16 additions & 12 deletions src/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,16 @@ export class Remote {
return
}

const logDir = this.getLogDir(featureSet)

// This ensures the Remote SSH extension resolves the host to execute the
// Coder binary properly.
//
// If we didn't write to the SSH config file, connecting would fail with
// "Host not found".
try {
this.storage.writeToCoderOutputChannel("Updating SSH config...")
await this.updateSSHConfig(workspaceRestClient, parts.label, parts.host, binaryPath, featureSet)
await this.updateSSHConfig(workspaceRestClient, parts.label, parts.host, binaryPath, logDir)
} catch (error) {
this.storage.writeToCoderOutputChannel(`Failed to configure SSH: ${error}`)
throw error
Expand All @@ -450,7 +452,7 @@ export class Remote {
return
}
disposables.push(this.showNetworkUpdates(pid))
this.commands.workspaceLogPath = path.join(this.storage.getLogPath(), `${pid}.log`)
this.commands.workspaceLogPath = logDir ? path.join(logDir, `${pid}.log`) : undefined
})

// Register the label formatter again because SSH overrides it!
Expand All @@ -476,20 +478,22 @@ export class Remote {
}

/**
* Format's the --log-dir argument for the ProxyCommand
* Return the --log-dir argument value for the ProxyCommand. It may be an
* empty string if the setting is not set or the cli does not support it.
*/
private async formatLogArg(featureSet: FeatureSet): Promise<string> {
private getLogDir(featureSet: FeatureSet): string {
if (!featureSet.proxyLogDirectory) {
return ""
}

// If the proxyLogDirectory is not set in the extension settings we don't send one.
// Question for Asher: How do VSCode extension settings behave in terms of semver for the extension?
const logDir = expandPath(String(vscode.workspace.getConfiguration().get("coder.proxyLogDirectory") ?? "").trim())
if (!logDir) {
return ""
}
return expandPath(String(vscode.workspace.getConfiguration().get("coder.proxyLogDirectory") ?? "").trim())
}

/**
* Formats the --log-dir argument for the ProxyCommand after making sure it
* has been created.
*/
private async formatLogArg(logDir: string): Promise<string> {
await fs.mkdir(logDir, { recursive: true })
this.storage.writeToCoderOutputChannel(`SSH proxy diagnostics are being written to ${logDir}`)
return ` --log-dir ${escape(logDir)}`
Expand All @@ -502,7 +506,7 @@ export class Remote {
label: string,
hostName: string,
binaryPath: string,
featureSet: FeatureSet,
logDir: string,
) {
let deploymentSSHConfig = {}
try {
Expand Down Expand Up @@ -585,7 +589,7 @@ export class Remote {
Host: label ? `${AuthorityPrefix}.${label}--*` : `${AuthorityPrefix}--*`,
ProxyCommand: `${escape(binaryPath)}${headerArg} vscodessh --network-info-dir ${escape(
this.storage.getNetworkInfoPath(),
)}${await this.formatLogArg(featureSet)} --session-token-file ${escape(this.storage.getSessionTokenPath(label))} --url-file ${escape(
)}${await this.formatLogArg(logDir)} --session-token-file ${escape(this.storage.getSessionTokenPath(label))} --url-file ${escape(
this.storage.getUrlPath(label),
)} %h`,
ConnectTimeout: "0",
Expand Down

0 comments on commit b0a965f

Please sign in to comment.