feat(core): return RefreshResult from ContextBridge.refresh()

Surfaces provider errors through RefreshResult.errors instead of
silently ignoring them.

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2026-01-18 20:28:54 +00:00
parent 037589cf4f
commit b73e603c90
2 changed files with 20 additions and 2 deletions

View File

@@ -5,6 +5,15 @@ interface ContextUpdatable {
pushContextUpdate(update: Partial<Context>): void pushContextUpdate(update: Partial<Context>): void
} }
export interface ProviderError {
key: string
error: Error
}
export interface RefreshResult {
errors: ProviderError[]
}
/** /**
* Bridges context providers to a feed controller. * Bridges context providers to a feed controller.
* *
@@ -55,10 +64,11 @@ export class ContextBridge {
/** /**
* Gathers current values from all providers and pushes to controller. * Gathers current values from all providers and pushes to controller.
* Use for manual refresh when user pulls to refresh. * Use for manual refresh when user pulls to refresh.
* Errors from individual providers are silently ignored. * Returns errors from providers that failed to fetch.
*/ */
async refresh(): Promise<void> { async refresh(): Promise<RefreshResult> {
const updates: Partial<Context> = {} const updates: Partial<Context> = {}
const errors: ProviderError[] = []
const entries = Array.from(this.providers.entries()) const entries = Array.from(this.providers.entries())
const results = await Promise.allSettled( const results = await Promise.allSettled(
@@ -69,10 +79,17 @@ export class ContextBridge {
const result = results[i] const result = results[i]
if (result?.status === "fulfilled") { if (result?.status === "fulfilled") {
updates[key] = result.value updates[key] = result.value
} else if (result?.status === "rejected") {
errors.push({
key,
error: result.reason instanceof Error ? result.reason : new Error(String(result.reason)),
})
} }
}) })
this.controller.pushContextUpdate(updates) this.controller.pushContextUpdate(updates)
return { errors }
} }
/** /**

View File

@@ -12,6 +12,7 @@ export type { DataSource } from "./data-source"
export type { ContextProvider } from "./context-provider" export type { ContextProvider } from "./context-provider"
// Context Bridge // Context Bridge
export type { ProviderError, RefreshResult } from "./context-bridge"
export { ContextBridge } from "./context-bridge" export { ContextBridge } from "./context-bridge"
// Reconciler // Reconciler