Skip to content

Commit 6b3adec

Browse files
committed
no nesting try-catch
1 parent b3a1f77 commit 6b3adec

File tree

1 file changed

+25
-32
lines changed

1 file changed

+25
-32
lines changed

packages/core/src/shared/lsp/utils/platform.ts

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -100,43 +100,36 @@ export async function getVSCodeSettings(): Promise<{ proxyUrl?: string; certific
100100
result.proxyUrl = proxy
101101
logger.info(`Using proxy from VS Code settings: ${proxy}`)
102102
}
103+
} catch (err) {
104+
logger.error(`Failed to get VS Code settings: ${err}`)
105+
return result
106+
}
107+
try {
108+
const tls = await import('tls')
109+
// @ts-ignore Get system certificates
110+
const systemCerts = tls.getCACertificates('system')
111+
// @ts-ignore Get any existing extra certificates
112+
const extraCerts = tls.getCACertificates('extra')
113+
const allCerts = [...systemCerts, ...extraCerts]
114+
if (allCerts && allCerts.length > 0) {
115+
logger.info(`Found ${allCerts.length} certificates in system's trust store`)
116+
117+
const tempDir = join(tmpdir(), 'aws-toolkit-vscode')
118+
if (!nodefs.existsSync(tempDir)) {
119+
nodefs.mkdirSync(tempDir, { recursive: true })
120+
}
103121

104-
try {
105-
const tls = await import('tls')
106-
107-
// @ts-ignore Get system certificates
108-
const systemCerts = tls.getCACertificates('system')
109-
110-
// @ts-ignore Get any existing extra certificates
111-
const extraCerts = tls.getCACertificates('extra')
112-
113-
// Combine all certificates
114-
const allCerts = [...systemCerts, ...extraCerts]
115-
if (allCerts && allCerts.length > 0) {
116-
logger.info(`Found ${allCerts.length} certificates in system's trust store`)
117-
118-
// Create a temporary file with certificates
119-
const tempDir = join(tmpdir(), 'aws-toolkit-vscode')
120-
if (!nodefs.existsSync(tempDir)) {
121-
nodefs.mkdirSync(tempDir, { recursive: true })
122-
}
123-
124-
const certPath = join(tempDir, 'vscode-ca-certs.pem')
125-
const certContent = allCerts.join('\n')
122+
const certPath = join(tempDir, 'vscode-ca-certs.pem')
123+
const certContent = allCerts.join('\n')
126124

127-
nodefs.writeFileSync(certPath, certContent)
128-
result.certificatePath = certPath
129-
logger.info(`Created certificate file at: ${certPath}`)
130-
}
131-
} catch (err) {
132-
logger.error(`Failed to extract certificates: ${err}`)
125+
nodefs.writeFileSync(certPath, certContent)
126+
result.certificatePath = certPath
127+
logger.info(`Created certificate file at: ${certPath}`)
133128
}
134-
135-
return result
136129
} catch (err) {
137-
logger.error(`Failed to get VS Code settings: ${err}`)
138-
return result
130+
logger.error(`Failed to extract certificates: ${err}`)
139131
}
132+
return result
140133
}
141134

142135
export function createServerOptions({

0 commit comments

Comments
 (0)