Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: bugfix
description: >
Validate file types when selecting custom rules for a profile. The file
dialog now filters to YAML rule files, and any non-YAML files that slip
through (e.g. on platforms where dialog filters are not enforced) are
skipped with a warning instead of being silently added to the profile.
Folders are still accepted as rule directories.
32 changes: 29 additions & 3 deletions vscode/core/src/utilities/profiles/profileActions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { basename } from "path";
import { ExtensionState } from "src/extensionState";
import { OpenDialogOptions, window } from "vscode";
import { FileType, OpenDialogOptions, Uri, window, workspace } from "vscode";
import { getUserProfiles, saveUserProfiles } from "./profileService";
import { updateConfigErrors } from "../configuration";

Expand All @@ -9,15 +10,40 @@ export async function handleConfigureCustomRules(profileId: string, state: Exten
canSelectFolders: true,
canSelectFiles: true,
openLabel: "Select Custom Rules",
filters: { "All Files": ["*"] },
filters: { "YAML rule files": ["yaml", "yml"] },
};

const fileUris = await window.showOpenDialog(options);
if (!fileUris || fileUris.length === 0) {
return;
}

const customRules = fileUris.map((uri) => uri.fsPath);
// Dialog filters don't apply to folders and are not enforced on all
// platforms, so validate the selection: directories are accepted as rule
// directories, files must be YAML.
const validUris: Uri[] = [];
const skippedNames: string[] = [];
for (const uri of fileUris) {
const stat = await workspace.fs.stat(uri);
const isDirectory = (stat.type & FileType.Directory) !== 0;
const isYamlFile = uri.fsPath.endsWith(".yaml") || uri.fsPath.endsWith(".yml");
if (isDirectory || isYamlFile) {
validUris.push(uri);
} else {
skippedNames.push(basename(uri.fsPath));
}
Comment on lines +21 to +34

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Locate file =="
git ls-files | rg '(^|/)profileActions\.ts$|profiles/profileActions\.ts$' || true

echo "== File outline/size =="
wc -l vscode/core/src/utilities/profiles/profileActions.ts
ast-grep outline vscode/core/src/utilities/profiles/profileActions.ts || true

echo "== Relevant file section =="
sed -n '1,120p' vscode/core/src/utilities/profiles/profileActions.ts

echo "== Search stat/usages of validUris/skippedNames =="
rg -n "workspace\.fs\.stat|validUris|skippedNames|getProfiles|save|yaml|yml" vscode/core/src/utilities/profiles/profileActions.ts

Repository: konveyor/editor-extensions

Length of output: 4702


🌐 Web query:

Microsoft VSCode API workspace.fs.stat Error FileSystemError stat does not find file throws documentation

💡 Result:

In the Visual Studio Code extension API, the vscode.workspace.fs.stat method is designed to throw a vscode.FileSystemError when the target file or folder cannot be found [1][2]. When implementing or consuming this API, you should handle this scenario using a try-catch block [1][2]. Specifically, when a file is missing, the API throws an error that satisfies e instanceof vscode.FileSystemError and whose name or code corresponds to FileNotFound [1][2][3]. Key technical details: - Error Handling: To verify if a file does not exist, wrap the stat call in a try-catch and check for the FileNotFound error [1][2]. - Implementation Requirements: If you are implementing a custom FileSystemProvider, you are expected to throw vscode.FileSystemError.FileNotFound() when a requested path does not exist [4]. This allows VS Code to correctly propagate the state and identify the missing file [4]. - Identification: You can identify the specific error type by checking the error object's name or code property, which will be set to FileNotFound [3][5]. Note that some custom FileSystemProvider implementations (such as specific Git provider versions) may behave inconsistently if not properly configured to throw these errors; however, the standard expectation for the vscode.workspace.fs.stat API is that it must signal a missing entry by throwing the appropriate FileSystemError [6][4].

Citations:


🌐 Web query:

VSCode FileSystemError.name FileNotFound stat throws error code name

💡 Result:

In the Visual Studio Code extension API, when implementing a FileSystemProvider—such as the stat method—you should throw a vscode.FileSystemError.FileNotFound error to indicate that a requested file or directory does not exist [1][2]. For your implementation, use the built-in factory method: throw vscode.FileSystemError.FileNotFound(uri); Key technical details regarding FileSystemError codes: 1. Identifying Errors: The FileSystemError class includes a code property that identifies the type of error [3][4]. This code corresponds to the class name of the factory method (e.g., 'FileNotFound') [3][5]. 2. Internal Mappings: Internally, VS Code maps these errors to specific provider error codes (like EntryNotFound) [6]. When you throw using the provided factory methods, the VS Code file service correctly handles and identifies these errors [1][7]. 3. Best Practice: Always use the static factory methods provided by the vscode.FileSystemError class (e.g., FileExists, FileNotADirectory, NoPermissions) rather than manually constructing an error object [1][5][8]. This ensures the error is correctly recognized by the host side of the VS Code API [1].

Citations:


Handle workspace.fs.stat failures per selection.

window.showOpenDialog can return stale or unsupported URIs, and workspace.fs.stat(uri) can throw before later selections are evaluated. Wrap each stat call in try/catch, track stat failures separately from non-YAML files, and continue evaluating the remaining selections.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@vscode/core/src/utilities/profiles/profileActions.ts` around lines 21 - 34,
Update the selection loop in profileActions to wrap each workspace.fs.stat call
in try/catch, recording failures separately from skipped non-YAML filenames and
continuing with subsequent URIs. Preserve the existing directory/YAML validation
for successful stats and ensure both failure categories remain available for
later handling.

}

if (skippedNames.length > 0) {
window.showWarningMessage(
`Skipped non-YAML file(s): ${skippedNames.join(", ")}. Custom rules must be .yaml or .yml files, or folders containing them.`,
);
}
if (validUris.length === 0) {
return;
}

const customRules = validUris.map((uri) => uri.fsPath);

const profile = state.data.profiles.find((p) => p.id === profileId);
if (!profile) {
Expand Down
Loading