Skip to content

Commit 3b26473

Browse files
authored
chore: add an error log when adapter is missing (#994)
## Description This PR introduces more discoverability to a potential common pitfall of user not calling initExecutorch, before using the resource fetcher. ### Introduces a breaking change? - [ ] Yes - [x] No ### Type of change - [ ] Bug fix (change which fixes an issue) - [ ] New feature (change which adds functionality) - [ ] Documentation update (improves or adds clarity to existing documentation) - [x] Other (chores, tests, code style improvements etc.) ### Tested on - [ ] 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 <!-- Link related issues here using #issue-number --> ### Checklist - [ ] 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 - [ ] 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 380e7d9 commit 3b26473

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { ResourceSource } from '../types/common';
3232
import { RnExecutorchError } from '../errors/errorUtils';
3333
import { RnExecutorchErrorCode } from '../errors/ErrorCodes';
3434
import { ResourceFetcherUtils } from './ResourceFetcherUtils';
35+
import { Logger } from '../common/Logger';
3536

3637
/**
3738
* Adapter interface for resource fetching operations.
@@ -104,9 +105,13 @@ export class ResourceFetcher {
104105
*/
105106
static getAdapter(): ResourceFetcherAdapter {
106107
if (!this.adapter) {
108+
const errorMessage =
109+
'ResourceFetcher adapter is not initialized. Please call initExecutorch({ resourceFetcher: ... }) with a valid adapter, e.g., from react-native-executorch-expo-resource-fetcher or react-native-executorch-bare-resource-fetcher. For more details please refer: https://docs.swmansion.com/react-native-executorch/docs/next/fundamentals/loading-models';
110+
// for sanity :)
111+
Logger.error(errorMessage);
107112
throw new RnExecutorchError(
108113
RnExecutorchErrorCode.ResourceFetcherAdapterNotInitialized,
109-
'ResourceFetcher adapter is not initialized. Please call initExecutorch({ resourceFetcher: ... }) with a valid adapter, e.g., from react-native-executorch-expo-resource-fetcher or react-native-executorch-bare-resource-fetcher. For more details please refer: https://docs.swmansion.com/react-native-executorch/docs/next/fundamentals/loading-models'
114+
errorMessage
110115
);
111116
}
112117
return this.adapter;

0 commit comments

Comments
 (0)