Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 84dccb5

Browse files
authored
Merge pull request #1163 from chris-reeves/fix-1162/formatting-wipes-out-unparsable-files
Handle non-zero exit status when formatting using shfmt
2 parents 2d51e28 + 522a5d6 commit 84dccb5

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

‎server/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Bash Language Server
22

3+
## 5.3.2
4+
5+
- Handle non-zero exit status when formatting using shfmt https://github.com/bash-lsp/bash-language-server/pull/1163
6+
37
## 5.3.1
48

59
- Clear diagnostics when closing document https://github.com/bash-lsp/bash-language-server/pull/1135

‎server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "A language server for Bash",
44
"author": "Mads Hartmann",
55
"license": "MIT",
6-
"version": "5.3.1",
6+
"version": "5.3.2",
77
"main": "./out/server.js",
88
"typings": "./out/server.d.ts",
99
"bin": {

‎server/src/shfmt/__tests__/index.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('formatter', () => {
3838
expect(new Formatter({ executablePath: 'foo' }).canFormat).toBe(true)
3939
})
4040

41-
it('should set canFormat to false when formatting fails', async () => {
41+
it('should set canFormat to false when the executable cannot be found', async () => {
4242
const [result, formatter] = await getFormattingResult({
4343
document: textToDoc(''),
4444
executablePath: 'foo',
@@ -54,6 +54,14 @@ describe('formatter', () => {
5454
)
5555
})
5656

57+
it('should throw when formatting fails', async () => {
58+
expect(async () => {
59+
await getFormattingResult({ document: FIXTURE_DOCUMENT.PARSE_PROBLEMS })
60+
}).rejects.toThrow(
61+
'Shfmt: exited with status 1: <standard input>:10:1: > must be followed by a word',
62+
)
63+
})
64+
5765
it('should format when shfmt is present', async () => {
5866
const [result] = await getFormattingResult({ document: FIXTURE_DOCUMENT.SHFMT })
5967
expect(result).toMatchInlineSnapshot(`

‎server/src/shfmt/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,10 @@ export class Formatter {
9191
proc.stdin.end(documentText)
9292
})
9393

94-
// NOTE: do we care about exit code? 0 means "ok", 1 possibly means "errors",
95-
// but the presence of parseable errors in the output is also sufficient to
96-
// distinguish.
9794
let exit
9895
try {
9996
exit = await proc
10097
} catch (e) {
101-
// TODO: we could do this up front?
10298
if ((e as any).code === 'ENOENT') {
10399
// shfmt path wasn't found, don't try to format any more:
104100
logger.warn(
@@ -107,7 +103,11 @@ export class Formatter {
107103
this._canFormat = false
108104
return ''
109105
}
110-
throw new Error(`Shfmt: failed with code ${exit}: ${e}\nout:\n${out}\nerr:\n${err}`)
106+
throw new Error(`Shfmt: child process error: ${e}`)
107+
}
108+
109+
if (exit != 0) {
110+
throw new Error(`Shfmt: exited with status ${exit}: ${err}`)
111111
}
112112

113113
return out

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /