debug pathselector for non-existing paths

This commit is contained in:
thatben 2025-04-08 15:27:13 +02:00
parent 574d4febe2
commit 7fa7820a53
No known key found for this signature in database
GPG Key ID: 62C543548433D43E
5 changed files with 33 additions and 3 deletions

View File

@ -30,6 +30,7 @@ import { ConfigMenu } from "./ui/configMenu.js";
import { PathSelector } from "./utils/pathSelector.js";
import { NumberSelector } from "./utils/numberSelector.js";
import { MenuLoop } from "./utils/menuLoop.js";
import { DataDirMover } from "./utils/dataDirMover.js";
async function showNavigationMenu() {
console.log("\n");

View File

@ -10,7 +10,7 @@ import {
const defaultConfig = {
codexExe: "",
// User-selected config options:
codexPath: getCodexBinPath(),
codexInstallPath: getCodexBinPath(),
dataDir: getCodexDataDirDefaultPath(),
logsDir: getCodexLogsDefaultPath(),
storageQuota: 8 * 1024 * 1024 * 1024,

14
src/utils/command.js Normal file
View File

@ -0,0 +1,14 @@
import { exec } from "child_process";
import { promisify } from "util";
export const execAsync = promisify(exec);
export async function runCommand(command) {
try {
const { stdout, stderr } = await execAsync(command);
return stdout;
} catch (error) {
console.error("Error:", error.message);
throw error;
}
}

View File

@ -140,8 +140,13 @@ export class PathSelector {
getSubDirOptions = () => {
const fullPath = this.combine(this.currentPath);
const entries = this.fs.readDir(fullPath);
return entries.filter((entry) => this.isSubDir(entry));
try {
const entries = this.fs.readDir(fullPath);
return entries.filter((entry) => this.isSubDir(entry));
}
catch {
return [];
}
};
downOne = async () => {

View File

@ -101,6 +101,16 @@ describe("PathSelector", () => {
expect(mockFsService.readDir).toHaveBeenCalledWith(mockStartPath);
});
it("handles non-existing paths", async () => {
mockFsService.readDir.mockImplementationOnce(() => { throw new Error("A!"); });
await pathSelector.downOne();
expect(mockUiService.showInfoMessage).toHaveBeenCalledWith(
"There are no subdirectories here."
);
});
it("can navigate to a subdirectory", async () => {
const subdir = "subdir1";
mockFsService.readDir.mockReturnValue([subdir]);