Skip to content

Improve error message when a workspace folder is inaccessible #1276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion packages/tailwindcss-language-server/src/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
import { URI } from 'vscode-uri'
import normalizePath from 'normalize-path'
import * as path from 'node:path'
import * as fs from 'node:fs/promises'
import type * as chokidar from 'chokidar'
import picomatch from 'picomatch'
import * as parcel from './watcher/index.js'
Expand Down Expand Up @@ -174,6 +175,26 @@ export class TW {
}

private async _initFolder(baseUri: URI): Promise<void> {
// NOTE: We do this check because 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.
let base = baseUri.fsPath

try {
await fs.access(base, fs.constants.F_OK | fs.constants.R_OK)
} catch (err) {
console.error(
`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.`,
)
console.error(err)
return
}

let initUserLanguages = this.initializeParams.initializationOptions?.userLanguages ?? {}

if (Object.keys(initUserLanguages).length > 0) {
Expand All @@ -182,7 +203,6 @@ export class TW {
)
}

let base = baseUri.fsPath
let workspaceFolders: Array<ProjectConfig> = []
let globalSettings = await this.settingsCache.get()
let ignore = globalSettings.tailwindCSS.files.exclude
Expand Down
1 change: 1 addition & 0 deletions packages/vscode-tailwindcss/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- v4: Add support for upcoming `@source not` feature ([#1262](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1262))
- v4: Add support for upcoming `@source inline(…)` feature ([#1262](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1262))
- LSP: Refresh internal caches when settings are updated ([#1273](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1273))
- 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))

# 0.14.9

Expand Down