Skip to content

Commit 016291a

Browse files
authored
Merge pull request #238 from bash-lsp/explainshell-exception
Do not crash if explainshell server is down or misconfigured
2 parents 71d1dca + be9c3d1 commit 016291a

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

server/src/server.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,28 @@ export default class BashServer {
201201
const explainshellEndpoint = config.getExplainshellEndpoint()
202202
if (explainshellEndpoint) {
203203
this.connection.console.log(`Query ${explainshellEndpoint}`)
204-
const response = await this.analyzer.getExplainshellDocumentation({
205-
params,
206-
endpoint: explainshellEndpoint,
207-
})
204+
try {
205+
const response = await this.analyzer.getExplainshellDocumentation({
206+
params,
207+
endpoint: explainshellEndpoint,
208+
})
208209

209-
if (response.status === 'error') {
210-
this.connection.console.log(
211-
`getExplainshellDocumentation returned: ${JSON.stringify(response, null, 4)}`,
212-
)
213-
} else {
214-
return {
215-
contents: {
216-
kind: 'markdown',
217-
value: new TurndownService().turndown(response.helpHTML),
218-
},
210+
if (response.status === 'error') {
211+
this.connection.console.log(
212+
`getExplainshellDocumentation returned: ${JSON.stringify(response, null, 4)}`,
213+
)
214+
} else {
215+
return {
216+
contents: {
217+
kind: 'markdown',
218+
value: new TurndownService().turndown(response.helpHTML),
219+
},
220+
}
219221
}
222+
} catch (error) {
223+
this.connection.console.warn(
224+
`getExplainshellDocumentation exception: ${error.message}`,
225+
)
220226
}
221227
}
222228

0 commit comments

Comments
 (0)