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
Changes from 1 commit
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
Next Next commit
Improve error message when a workspace folder is inaccessible
  • Loading branch information
thecrypticace committed Mar 20, 2025
commit a740944e23246d01e5287f67a1aa3d6cc1588c64
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)
} 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