Skip to content

Commit 1eb8700

Browse files
rizalibnumsluszniak
authored andcommitted
fix: handle directory creation errors in ResourceFetcherUtils
1 parent e6e9126 commit 1eb8700

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

packages/bare-adapter/src/ResourceFetcherUtils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
DownloadStatus,
88
SourceType,
99
ResourceSourceExtended,
10+
RnExecutorchError,
11+
RnExecutorchErrorCode,
1012
} from 'react-native-executorch';
1113
import { Image } from 'react-native';
1214
import * as RNFS from '@dr.pogodin/react-native-fs';
@@ -82,7 +84,15 @@ export namespace ResourceFetcherUtils {
8284

8385
export async function createDirectoryIfNoExists() {
8486
if (!(await checkFileExists(RNEDirectory))) {
85-
await RNFS.mkdir(RNEDirectory);
87+
try {
88+
await RNFS.mkdir(RNEDirectory);
89+
} catch (error) {
90+
throw new RnExecutorchError(
91+
RnExecutorchErrorCode.AccessFailed,
92+
`Failed to create directory at ${RNEDirectory}`,
93+
error
94+
);
95+
}
8696
}
8797
}
8898

packages/expo-adapter/src/ResourceFetcherUtils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
DownloadStatus,
88
SourceType,
99
ResourceSourceExtended,
10+
RnExecutorchError,
11+
RnExecutorchErrorCode,
1012
} from 'react-native-executorch';
1113
import { Asset } from 'expo-asset';
1214

@@ -95,7 +97,15 @@ export namespace ResourceFetcherUtils {
9597

9698
export async function createDirectoryIfNoExists() {
9799
if (!(await checkFileExists(RNEDirectory))) {
98-
await makeDirectoryAsync(RNEDirectory, { intermediates: true });
100+
try {
101+
await makeDirectoryAsync(RNEDirectory, { intermediates: true });
102+
} catch (error) {
103+
throw new RnExecutorchError(
104+
RnExecutorchErrorCode.AccessFailed,
105+
`Failed to create directory at ${RNEDirectory}`,
106+
error
107+
);
108+
}
99109
}
100110
}
101111

0 commit comments

Comments
 (0)