Skip to content

Commit 06f6b0f

Browse files
fix: wrap the try-catch block only around the URL parsing block rather than whole logic
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent dd8a8df commit 06f6b0f

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/run/index.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,23 @@ export default async (cmd) => {
178178
fs.mkdirSync(toolOutputDir);
179179

180180
for (const url of urls) {
181+
for (const url of urls) {
182+
// Validate URL only
183+
let urlObj;
181184
try {
182-
let urlTest = new URL(url);
183-
const thisTargetWorkingDir = toolOutputDir + "/" + new URL(url).host.replace(":", "_");
184-
fs.mkdirSync(thisTargetWorkingDir);
185-
const outputDir = thisTargetWorkingDir + "/output";
186-
await processUrl(url, outputDir, thisTargetWorkingDir, cmd, true);
187-
} catch (e) {
185+
urlObj = new URL(url);
186+
} catch {
188187
console.log(chalk.bgRed(`[!] Invalid URL: ${url}`));
188+
continue;
189+
}
190+
191+
const thisTargetWorkingDir = `${toolOutputDir}/${urlObj.host.replace(":", "_")}`;
192+
if (!fs.existsSync(thisTargetWorkingDir)) {
193+
fs.mkdirSync(thisTargetWorkingDir, { recursive: true });
189194
}
195+
const outputDir = `${thisTargetWorkingDir}/output`;
196+
await processUrl(url, outputDir, thisTargetWorkingDir, cmd, true);
197+
}
190198
}
191199
}
192200
};

0 commit comments

Comments
 (0)