(defaultPath: string)
| 12 | * Otherwise uses the default VSCode extension global storage path |
| 13 | */ |
| 14 | export async function getStorageBasePath(defaultPath: string): Promise<string> { |
| 15 | // Get user-configured custom storage path |
| 16 | let customStoragePath = "" |
| 17 | |
| 18 | try { |
| 19 | // This is the line causing the error in tests |
| 20 | const config = vscode.workspace.getConfiguration(Package.name) |
| 21 | customStoragePath = config.get<string>("customStoragePath", "") |
| 22 | } catch (error) { |
| 23 | console.warn("Could not access VSCode configuration - using default path") |
| 24 | return defaultPath |
| 25 | } |
| 26 | |
| 27 | // If no custom path is set, use default path |
| 28 | if (!customStoragePath) { |
| 29 | return defaultPath |
| 30 | } |
| 31 | |
| 32 | try { |
| 33 | // Ensure custom path exists |
| 34 | await fs.mkdir(customStoragePath, { recursive: true }) |
| 35 | |
| 36 | // Check directory write permission without creating temp files |
| 37 | await fs.access(customStoragePath, fsConstants.R_OK | fsConstants.W_OK | fsConstants.X_OK) |
| 38 | |
| 39 | return customStoragePath |
| 40 | } catch (error) { |
| 41 | // If path is unusable, report error and fall back to default path |
| 42 | console.error(`Custom storage path is unusable: ${error instanceof Error ? error.message : String(error)}`) |
| 43 | if (vscode.window) { |
| 44 | vscode.window.showErrorMessage(t("common:errors.custom_storage_path_unusable", { path: customStoragePath })) |
| 45 | } |
| 46 | return defaultPath |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Gets the storage directory path for a task |
no test coverage detected