aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Czihak <git@dcz.at>2026-05-08 21:15:26 +0200
committerDavid Czihak <git@dcz.at>2026-05-08 21:15:26 +0200
commit8ddd84baba48df6c146f2d15fd017d7928473d41 (patch)
tree34c7ec3c6f32fdf7d4d1fb96318d98e938d4ee56
parent8dfe15aa16c51eb7eca0c2edaedcb83b5f8a92d0 (diff)
Fix: Stability improvements in utils
Resource leak, null guards, and promise rejection in process utilities.
-rw-r--r--Scripts/main.js33
1 files changed, 21 insertions, 12 deletions
diff --git a/Scripts/main.js b/Scripts/main.js
index e3e175b..944eb62 100644
--- a/Scripts/main.js
+++ b/Scripts/main.js
@@ -199,7 +199,7 @@ function buildZigArgv(config, options) {
// Refuses to clean unless `cwd` is non-root, not $HOME, and inside the workspace.
// Returns the array of cache directories to remove, or null after warning the user.
-function safeCleanPaths(cwd) {
+function resolveCleanPaths(cwd) {
const showWarning = () => {
nova.workspace.showWarningMessage(
localizeText(
@@ -250,7 +250,7 @@ function safeCleanPaths(cwd) {
// Walks up from `startDir` to the nearest ancestor containing `build.zig`,
// stopping at the workspace root. Returns the workspace root if no build.zig
// is found above startDir, or null if no workspace is open.
-function nearestBuildZigDir(startDir) {
+function findNearestZigBuildDir(startDir) {
const workspacePath = nova.workspace.path
? nova.path.normalize(nova.workspace.path)
: null;
@@ -284,9 +284,13 @@ function parseProjectName(cwd) {
let content = "";
try {
const file = nova.fs.open(zonPath, "r");
- content = file.read() || "";
- file.close();
- } catch (_) {
+ try {
+ content = file.read() || "";
+ } finally {
+ file.close();
+ }
+ } catch (error) {
+ console.warn(`[zig] Failed to read ${zonPath}: ${error}`);
return null;
}
if (typeof content !== "string" || content.length === 0) return null;
@@ -423,7 +427,7 @@ function localizeText(key, fallback, variables) {
}
function runProcess(command, options) {
- return new Promise((resolve) => {
+ return new Promise((resolve, reject) => {
const stdout = [];
const stderr = [];
const process = new Process(command, options || {});
@@ -438,13 +442,17 @@ function runProcess(command, options) {
});
});
- process.start();
+ try {
+ process.start();
+ } catch (error) {
+ reject(error);
+ }
});
}
-async function findOnPath(commandName) {
+async function findOnPath(executableName) {
const result = await runProcess("/usr/bin/env", {
- args: ["which", commandName],
+ args: ["which", executableName],
});
if (result.status !== 0) {
@@ -551,7 +559,8 @@ function quoteShellArgument(value) {
}
function escapeAppleScriptString(value) {
- return String(value).replace(/\\/g, "\\\\").replace(/"/g, '\\"');
+ const text = value === null || value === undefined ? "" : String(value);
+ return text.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
}
function buildShellCommand(command, args, cwd) {
@@ -992,7 +1001,7 @@ class ZigTaskAssistant {
return null;
}
- const paths = safeCleanPaths(cwd);
+ const paths = resolveCleanPaths(cwd);
if (!paths) return null;
// If the project exposes an `uninstall` step, prefer running it before
@@ -1150,7 +1159,7 @@ class ZigTaskAssistant {
return null;
}
- const cwd = nearestBuildZigDir(startDir);
+ const cwd = findNearestZigBuildDir(startDir);
return this.resolveCleanAction(cwd);
}