Skip to content

Commit 8a2ea81

Browse files
Fix: Resource Fetcher not loading downloaded models (#564)
## Description Fixes a resource fetcher bug, which prevented from actually loading downloaded models without internet connection. Issue occurred due to the wrong error handling in the process of fetching head (to get the content length) of the resource. ### Introduces a breaking change? - [ ] Yes - [x] No ### Type of change - [x] Bug fix (change which fixes an issue) - [ ] New feature (change which adds functionality) - [ ] Documentation update (improves or adds clarity to existing documentation) - [ ] Other (chores, tests, code style improvements etc.) ### Tested on - [x] iOS - [ ] Android ### Testing instructions <!-- Provide step-by-step instructions on how to test your changes. Include setup details if necessary. --> ### Screenshots <!-- Add screenshots here, if applicable --> ### Related issues Closes #563 ### Checklist - [x] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [x] My changes generate no new warnings ### Additional notes <!-- Include any additional information, assumptions, or context that reviewers might need to understand this PR. -->
1 parent 4344c09 commit 8a2ea81

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

packages/react-native-executorch/src/utils/ResourceFetcherUtils.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ export namespace ResourceFetcherUtils {
7878
for (const source of sources) {
7979
const type = await ResourceFetcherUtils.getType(source);
8080
let length = 0;
81-
82-
if (type === SourceType.REMOTE_FILE && typeof source === 'string') {
83-
try {
81+
try {
82+
if (type === SourceType.REMOTE_FILE && typeof source === 'string') {
8483
const response = await fetch(source, { method: 'HEAD' });
8584
if (!response.ok) {
8685
Logger.warn(
@@ -97,14 +96,14 @@ export namespace ResourceFetcherUtils {
9796
length = contentLength ? parseInt(contentLength, 10) : 0;
9897
previousFilesTotalLength = totalLength;
9998
totalLength += length;
100-
} catch (error) {
101-
Logger.warn(`Error fetching HEAD for ${source}:`, error);
102-
continue;
10399
}
100+
} catch (error) {
101+
Logger.warn(`Error fetching HEAD for ${source}:`, error);
102+
continue;
103+
} finally {
104+
results.push({ source, type, length, previousFilesTotalLength });
104105
}
105-
results.push({ source, type, length, previousFilesTotalLength });
106106
}
107-
108107
return { results, totalLength };
109108
}
110109

0 commit comments

Comments
 (0)