Skip to content

Commit f91a3bc

Browse files
Improve error message when a workspace folder is inaccessible (#1276)
On Linux when using a LSP client that does not support watching files on behalf of the server, we'll use Parcel Watcher (if possible). If we start the watcher with a non-existent or inaccessible directory, it will throw an error with a very unhelpful message: "Bad file descriptor". The best thing we can do is an initial check for access to the directory and log a more helpful error message if it fails: <img width="1013" alt="Screenshot 2025-03-20 at 12 33 29" src="https://github.com/user-attachments/assets/425c1fac-cd5e-492f-89bf-76d3a733670d" /> See #884 (comment) --------- Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
1 parent 747884f commit f91a3bc

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/tailwindcss-language-server/src/tw.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
import { URI } from 'vscode-uri'
3939
import normalizePath from 'normalize-path'
4040
import * as path from 'node:path'
41+
import * as fs from 'node:fs/promises'
4142
import type * as chokidar from 'chokidar'
4243
import picomatch from 'picomatch'
4344
import * as parcel from './watcher/index.js'
@@ -174,6 +175,26 @@ export class TW {
174175
}
175176

176177
private async _initFolder(baseUri: URI): Promise<void> {
178+
// NOTE: We do this check because on Linux when using an LSP client that does
179+
// not support watching files on behalf of the server, we'll use Parcel
180+
// Watcher (if possible). If we start the watcher with a non-existent or
181+
// inaccessible directory, it will throw an error with a very unhelpful
182+
// message: "Bad file descriptor"
183+
//
184+
// The best thing we can do is an initial check for access to the directory
185+
// and log a more helpful error message if it fails.
186+
let base = baseUri.fsPath
187+
188+
try {
189+
await fs.access(base, fs.constants.F_OK | fs.constants.R_OK)
190+
} catch (err) {
191+
console.error(
192+
`Unable to access the workspace folder [${base}]. This may happen if the directory does not exist or the current user does not have the necessary permissions to access it.`,
193+
)
194+
console.error(err)
195+
return
196+
}
197+
177198
let initUserLanguages = this.initializeParams.initializationOptions?.userLanguages ?? {}
178199

179200
if (Object.keys(initUserLanguages).length > 0) {
@@ -182,7 +203,6 @@ export class TW {
182203
)
183204
}
184205

185-
let base = baseUri.fsPath
186206
let workspaceFolders: Array<ProjectConfig> = []
187207
let globalSettings = await this.settingsCache.get()
188208
let ignore = globalSettings.tailwindCSS.files.exclude

packages/vscode-tailwindcss/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- v4: Add support for upcoming `@source not` feature ([#1262](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1262))
88
- v4: Add support for upcoming `@source inline(…)` feature ([#1262](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1262))
99
- LSP: Refresh internal caches when settings are updated ([#1273](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1273))
10+
- LSP: Improve error message when a workspace folder does not exist or is inaccesible to the current user ([#1276](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1276))
1011

1112
# 0.14.9
1213

0 commit comments

Comments
 (0)