Skip to content

Commit 41252b0

Browse files
committed
Handle broken symlinks (or other file read errors)
1 parent 7b75dee commit 41252b0

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

server/src/analyser.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,18 @@ export default class Analyzer {
6666
const uri = `file://${filePath}`
6767
connection.console.log(`Analyzing ${uri}`)
6868

69-
const fileContent = fs.readFileSync(filePath, 'utf8')
70-
71-
const shebang = getShebang(fileContent)
72-
if (shebang && !isBashShebang(shebang)) {
73-
connection.console.log(`Skipping file ${uri} with shebang "${shebang}"`)
74-
return
69+
try {
70+
const fileContent = fs.readFileSync(filePath, 'utf8')
71+
const shebang = getShebang(fileContent)
72+
if (shebang && !isBashShebang(shebang)) {
73+
connection.console.log(`Skipping file ${uri} with shebang "${shebang}"`)
74+
return
75+
}
76+
77+
analyzer.analyze(uri, LSP.TextDocument.create(uri, 'shell', 1, fileContent))
78+
} catch (error) {
79+
connection.console.warn(`Failed analyzing ${uri}. Error: ${error.message}`)
7580
}
76-
77-
analyzer.analyze(uri, LSP.TextDocument.create(uri, 'shell', 1, fileContent))
7881
})
7982

8083
connection.console.log(`Analyzer finished after ${getTimePassed()}`)

testing/fixtures/broken-symlink.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x.sh

0 commit comments

Comments
 (0)