ramensoftware/windhawk · error

No workspace folder

Error message

No workspace folder

What it means

EditorWorkspaceUtils requires a VS Code workspace to resolve mod file paths. In its constructor it reads the first entry of vscode.workspace.workspaceFolders; if the array is empty or undefined (no folder open), it triggers the 'workbench.action.files.openFolder' dialog and throws this error instead of constructing in an invalid state.

Solutions

  1. Open a workspace folder first (File > Open Folder); the constructor already pops the open-folder dialog, so just choose a folder and retry the command.
  2. Check vscode.workspace.workspaceFolders?.length > 0 before invoking commands that construct EditorWorkspaceUtils.
  3. If this happens in tests or automation, create/open a workspace (vscode.openFolder or a multi-root workspace file) in setup before the extension runs.

Example fix

// before
const utils = new EditorWorkspaceUtils();
// after
if (vscode.workspace.workspaceFolders?.length) {
  const utils = new EditorWorkspaceUtils();
} else {
  vscode.window.showErrorMessage('Open a folder first.');
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!vscode.workspace.workspaceFolders?.length) {
  vscode.window.showErrorMessage('Open a workspace folder before using this command.');
  return;
}

Try / catch

try {
  const utils = new EditorWorkspaceUtils();
} catch (e) {
  if (e.message === 'No workspace folder') {
    // constructor already offered the open-folder dialog; abort quietly
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Instantiating new EditorWorkspaceUtils() (directly or via a command/registration that constructs it) while VS Code has no workspace folder open — e.g. running a Windhawk extension command from an empty window or a single untitled file with no folder.

Common situations: Launching a fresh VS Code window and invoking a mod-related command before opening a folder; automation/test harnesses that activate the extension without a workspace; remote scenarios where the workspace failed to load.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


AI-assisted analysis of ramensoftware/windhawk@61d99ed8e1 (2026-09-12). Data as JSON: /api/errors/0a8dc1a293109be8. Report an issue: GitHub.

Appendix: source

Thrown at src/windhawk-vscode/src/utils/editorWorkspaceUtils.ts:20

import * as path from 'path';
import * as child_process from 'child_process';
import * as vscode from 'vscode';
import config from '../config';

// The charset the core enforces on a mod's @id (domain validate_metadata), kept
// here because ids reach paths by plain interpolation and sanitize nothing.
function isValidModId(modId: string) {
	return /^[0-9a-z-]+$/.test(modId);
}

export default class EditorWorkspaceUtils {
	private workspacePath: string;

	public constructor() {
		const firstWorkspaceFolder = vscode.workspace.workspaceFolders?.[0];
		if (!firstWorkspaceFolder) {
			vscode.commands.executeCommand('workbench.action.files.openFolder');
			throw new Error('No workspace folder');
		}

		this.workspacePath = firstWorkspaceFolder.uri.fsPath;
	}

	public getFilePath(fileName: string) {
		return path.join(this.workspacePath, fileName);
	}

	public getWorkspaceFolder() {
		return this.workspacePath;
	}

	public getModSourcePath() {
		return this.getFilePath('mod.wh.cpp');
	}

	public writePchHeader(content: string) {

View on GitHub (pinned to 61d99ed8e1)