Skip to content

Commit a198d54

Browse files
authored
fix(hooks): recognize cross-realm filesystem errors (#621)
1 parent 89f2bbc commit a198d54

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎packages/rstack/src/setup/install.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
writeFileSync,
88
} from 'node:fs';
99
import path from 'node:path';
10+
import { types } from 'node:util';
1011
import {
1112
displayPath,
1213
fail,
@@ -25,6 +26,8 @@ import { createHookFiles, hookNames } from './hooks.ts';
2526

2627
const defaultHooksDir = '.rstack/hooks';
2728
const gitignore = '*\n';
29+
const isError = (value: unknown): value is Error =>
30+
Error.isError?.(value) ?? types.isNativeError(value);
2831

2932
type InstallHooksOptions = {
3033
cwd?: string;
@@ -155,8 +158,7 @@ const claimOwner = (
155158
// Exclusive creation makes concurrent prepare scripts agree on one owner.
156159
writeFileSync(ownerPath, `${project}\n`, { flag: 'wx' });
157160
} catch (error) {
158-
const code =
159-
error instanceof Error && 'code' in error ? error.code : undefined;
161+
const code = isError(error) && 'code' in error ? error.code : undefined;
160162
if (code !== 'EEXIST') {
161163
throw error;
162164
}
@@ -285,7 +287,7 @@ export const installHooks = ({
285287
chmodSync(filePath, 0o755);
286288
}
287289
} catch (error) {
288-
const message = error instanceof Error ? error.message : String(error);
290+
const message = isError(error) ? error.message : String(error);
289291
return fail('write-failed', `Failed to write Git hook files: ${message}`);
290292
}
291293

0 commit comments

Comments
 (0)