Skip to content

Commit 652fb79

Browse files
authored
fix: add error parameters to Lychee action to catch blocks for Node.js compatibility (#1547)
## Description This PR fixes a potential syntax error in the link checker script that was causing issues in [GitHub Actions run #17112743303](https://github.com/wandb/docs/actions/runs/17112743303/job/48537533886#step:7:32). ## Problem The `fix_broken_links.mjs` script was using optional catch binding syntax (`catch {}` without an error parameter), which might not be supported in all Node.js environments or could be causing parsing issues in the GitHub Actions runner. ## Solution Updated all catch blocks to include the error parameter: - `catch {}` → `catch (e) {}` This ensures compatibility across different Node.js versions and environments. ## Changes - Updated 4 catch blocks in `fix_broken_links.mjs`: - Line 32: `normalizeUrl` function - Line 115: Controller cleanup in `probeRedirect` - Line 146: URL parsing in `candidateVariants` - Line 231: URL manipulation in `generateFromCandidates` ## Testing The updated code maintains the same functionality while being more compatible with different JavaScript environments. The error parameter is added but not used (as was the original intent with optional catch binding).
1 parent ecf4db2 commit 652fb79

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

.github/scripts/fix_broken_links.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function normalizeUrl(u) {
2929
try {
3030
const url = new URL(u);
3131
return url.toString();
32-
} catch {
32+
} catch (e) {
3333
return u;
3434
}
3535
}
@@ -112,7 +112,7 @@ async function probeRedirect(url) {
112112
} catch (e) {
113113
return { ok: false, finalUrl: url, error: String(e) };
114114
} finally {
115-
for (const c of controllers) try { c.abort(); } catch {}
115+
for (const c of controllers) try { c.abort(); } catch (e) {}
116116
}
117117
}
118118

@@ -143,7 +143,7 @@ function candidateVariants(url) {
143143
u.hostname = 'www.' + u.hostname;
144144
variants.push(u.toString());
145145
}
146-
} catch {
146+
} catch (e) {
147147
// ignore parse errors
148148
}
149149
return unique(variants).filter(v => v !== url);
@@ -228,7 +228,7 @@ function generateFromCandidates(fromUrl) {
228228
withSlash.pathname = withSlash.pathname + '/';
229229
set.add(withSlash.toString());
230230
}
231-
} catch {}
231+
} catch (e) {}
232232
return Array.from(set);
233233
}
234234

0 commit comments

Comments
 (0)