Skip to content

Commit 4fe8d87

Browse files
authored
docs: Clarify the behavior of setProviderAndWait (#1180)
## This PR - Updates readme examples to include a try/catch around setProviderAndWait - Improves the setProviderAndWait JS Doc ### Related Issues Fixes #1179 ### Notes https://cloud-native.slack.com/archives/C0344AANLA1/p1745326882304199 --------- Signed-off-by: Michael Beemer <[email protected]>
1 parent a259b90 commit 4fe8d87

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

packages/server/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ yarn add @openfeature/server-sdk @openfeature/core
7575
import { OpenFeature } from '@openfeature/server-sdk';
7676

7777
// Register your feature flag provider
78-
await OpenFeature.setProviderAndWait(new YourProviderOfChoice());
78+
try {
79+
await OpenFeature.setProviderAndWait(new YourProviderOfChoice());
80+
} catch (error) {
81+
console.error('Failed to initialize provider:', error);
82+
}
7983

8084
// create a new client
8185
const client = OpenFeature.getClient();

packages/server/src/open-feature.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class OpenFeatureAPI
8282
* Setting a provider supersedes the current provider used in new and existing unbound clients.
8383
* @param {Provider} provider The provider responsible for flag evaluations.
8484
* @returns {Promise<void>}
85-
* @throws Uncaught exceptions thrown by the provider during initialization.
85+
* @throws {Error} If the provider throws an exception during initialization.
8686
*/
8787
setProviderAndWait(provider: Provider): Promise<void>;
8888
/**
@@ -92,7 +92,7 @@ export class OpenFeatureAPI
9292
* @param {string} domain The name to identify the client
9393
* @param {Provider} provider The provider responsible for flag evaluations.
9494
* @returns {Promise<void>}
95-
* @throws Uncaught exceptions thrown by the provider during initialization.
95+
* @throws {Error} If the provider throws an exception during initialization.
9696
*/
9797
setProviderAndWait(domain: string, provider: Provider): Promise<void>;
9898
async setProviderAndWait(domainOrProvider?: string | Provider, providerOrUndefined?: Provider): Promise<void> {

packages/web/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ yarn add @openfeature/web-sdk @openfeature/core
7575
import { OpenFeature } from '@openfeature/web-sdk';
7676

7777
// Register your feature flag provider
78-
await OpenFeature.setProviderAndWait(new YourProviderOfChoice());
78+
try {
79+
await OpenFeature.setProviderAndWait(new YourProviderOfChoice());
80+
} catch (error) {
81+
console.error('Failed to initialize provider:', error);
82+
}
7983

8084
// create a new client
8185
const client = OpenFeature.getClient();
@@ -121,7 +125,11 @@ Once you've added a provider as a dependency, it can be registered with OpenFeat
121125
To register a provider and ensure it is ready before further actions are taken, you can use the `setProviderAndWait` method as shown below:
122126

123127
```ts
124-
await OpenFeature.setProviderAndWait(new MyProvider());
128+
try {
129+
await OpenFeature.setProviderAndWait(new MyProvider());
130+
} catch (error) {
131+
console.error('Failed to initialize provider:', error);
132+
}
125133
```
126134

127135
#### Synchronous

packages/web/src/open-feature.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class OpenFeatureAPI
7777
* Setting a provider supersedes the current provider used in new and existing unbound clients.
7878
* @param {Provider} provider The provider responsible for flag evaluations.
7979
* @returns {Promise<void>}
80-
* @throws Uncaught exceptions thrown by the provider during initialization.
80+
* @throws {Error} If the provider throws an exception during initialization.
8181
*/
8282
setProviderAndWait(provider: Provider): Promise<void>;
8383
/**
@@ -87,7 +87,7 @@ export class OpenFeatureAPI
8787
* @param {Provider} provider The provider responsible for flag evaluations.
8888
* @param {EvaluationContext} context The evaluation context to use for flag evaluations.
8989
* @returns {Promise<void>}
90-
* @throws Uncaught exceptions thrown by the provider during initialization.
90+
* @throws {Error} If the provider throws an exception during initialization.
9191
*/
9292
setProviderAndWait(provider: Provider, context: EvaluationContext): Promise<void>;
9393
/**
@@ -97,7 +97,7 @@ export class OpenFeatureAPI
9797
* @param {string} domain The name to identify the client
9898
* @param {Provider} provider The provider responsible for flag evaluations.
9999
* @returns {Promise<void>}
100-
* @throws Uncaught exceptions thrown by the provider during initialization.
100+
* @throws {Error} If the provider throws an exception during initialization.
101101
*/
102102
setProviderAndWait(domain: string, provider: Provider): Promise<void>;
103103
/**
@@ -108,7 +108,7 @@ export class OpenFeatureAPI
108108
* @param {Provider} provider The provider responsible for flag evaluations.
109109
* @param {EvaluationContext} context The evaluation context to use for flag evaluations.
110110
* @returns {Promise<void>}
111-
* @throws Uncaught exceptions thrown by the provider during initialization.
111+
* @throws {Error} If the provider throws an exception during initialization.
112112
*/
113113
setProviderAndWait(domain: string, provider: Provider, context: EvaluationContext): Promise<void>;
114114
async setProviderAndWait(

0 commit comments

Comments
 (0)