diff options
Diffstat (limited to 'src/state')
24 files changed, 83 insertions, 65 deletions
diff --git a/src/state/index.ts b/src/state/index.ts index 42687a229..2c81c0ddf 100644 --- a/src/state/index.ts +++ b/src/state/index.ts @@ -25,7 +25,7 @@ export async function setupState(serviceUri = DEFAULT_SERVICE) { rootStore.log.debug('Initial hydrate', {hasSession: !!data.session}) rootStore.hydrate(data) } catch (e: any) { - rootStore.log.error('Failed to load state from storage', e) + rootStore.log.error('Failed to load state from storage', {error: e}) } rootStore.attemptSessionResumption() diff --git a/src/state/models/content/feed-source.ts b/src/state/models/content/feed-source.ts index 8dac9b56f..d1b8fc9dc 100644 --- a/src/state/models/content/feed-source.ts +++ b/src/state/models/content/feed-source.ts @@ -134,7 +134,7 @@ export class FeedSourceModel { try { await this.rootStore.preferences.addSavedFeed(this.uri) } catch (error) { - this.rootStore.log.error('Failed to save feed', error) + this.rootStore.log.error('Failed to save feed', {error}) } finally { track('CustomFeed:Save') } @@ -147,7 +147,7 @@ export class FeedSourceModel { try { await this.rootStore.preferences.removeSavedFeed(this.uri) } catch (error) { - this.rootStore.log.error('Failed to unsave feed', error) + this.rootStore.log.error('Failed to unsave feed', {error}) } finally { track('CustomFeed:Unsave') } @@ -157,7 +157,7 @@ export class FeedSourceModel { try { await this.rootStore.preferences.addPinnedFeed(this.uri) } catch (error) { - this.rootStore.log.error('Failed to pin feed', error) + this.rootStore.log.error('Failed to pin feed', {error}) } finally { track('CustomFeed:Pin', { name: this.displayName, @@ -194,7 +194,7 @@ export class FeedSourceModel { } catch (e: any) { this.likeUri = undefined this.likeCount = (this.likeCount || 1) - 1 - this.rootStore.log.error('Failed to like feed', e) + this.rootStore.log.error('Failed to like feed', {error: e}) } finally { track('CustomFeed:Like') } @@ -215,7 +215,7 @@ export class FeedSourceModel { } catch (e: any) { this.likeUri = uri this.likeCount = (this.likeCount || 0) + 1 - this.rootStore.log.error('Failed to unlike feed', e) + this.rootStore.log.error('Failed to unlike feed', {error: e}) } finally { track('CustomFeed:Unlike') } diff --git a/src/state/models/content/list.ts b/src/state/models/content/list.ts index 8fb9f4b5e..985d8d82d 100644 --- a/src/state/models/content/list.ts +++ b/src/state/models/content/list.ts @@ -339,7 +339,7 @@ export class ListModel { try { await this.rootStore.preferences.addPinnedFeed(this.uri) } catch (error) { - this.rootStore.log.error('Failed to pin feed', error) + this.rootStore.log.error('Failed to pin feed', {error}) } finally { track('CustomFeed:Pin', { name: this.data?.name || '', @@ -455,10 +455,12 @@ export class ListModel { this.error = cleanError(err) this.loadMoreError = cleanError(loadMoreErr) if (err) { - this.rootStore.log.error('Failed to fetch user items', err) + this.rootStore.log.error('Failed to fetch user items', {error: err}) } if (loadMoreErr) { - this.rootStore.log.error('Failed to fetch user items', loadMoreErr) + this.rootStore.log.error('Failed to fetch user items', { + error: loadMoreErr, + }) } } diff --git a/src/state/models/content/post-thread.ts b/src/state/models/content/post-thread.ts index a862c27d3..cf6377da7 100644 --- a/src/state/models/content/post-thread.ts +++ b/src/state/models/content/post-thread.ts @@ -163,7 +163,7 @@ export class PostThreadModel { this.hasLoaded = true this.error = cleanError(err) if (err) { - this.rootStore.log.error('Failed to fetch post thread', err) + this.rootStore.log.error('Failed to fetch post thread', {error: err}) } this.notFound = err instanceof GetPostThread.NotFoundError } diff --git a/src/state/models/content/profile.ts b/src/state/models/content/profile.ts index 5333e7116..0050970e6 100644 --- a/src/state/models/content/profile.ts +++ b/src/state/models/content/profile.ts @@ -235,7 +235,7 @@ export class ProfileModel { this.hasLoaded = true this.error = cleanError(err) if (err) { - this.rootStore.log.error('Failed to fetch profile', err) + this.rootStore.log.error('Failed to fetch profile', {error: err}) } } diff --git a/src/state/models/discovery/feeds.ts b/src/state/models/discovery/feeds.ts index 1a00f802c..3902f3ac1 100644 --- a/src/state/models/discovery/feeds.ts +++ b/src/state/models/discovery/feeds.ts @@ -120,7 +120,7 @@ export class FeedsDiscoveryModel { this.hasLoaded = true this.error = cleanError(err) if (err) { - this.rootStore.log.error('Failed to fetch popular feeds', err) + this.rootStore.log.error('Failed to fetch popular feeds', {error: err}) } } diff --git a/src/state/models/discovery/suggested-actors.ts b/src/state/models/discovery/suggested-actors.ts index d270267ee..8776fcd85 100644 --- a/src/state/models/discovery/suggested-actors.ts +++ b/src/state/models/discovery/suggested-actors.ts @@ -144,7 +144,7 @@ export class SuggestedActorsModel { this.hasLoaded = true this.error = cleanError(err) if (err) { - this.rootStore.log.error('Failed to fetch suggested actors', err) + this.rootStore.log.error('Failed to fetch suggested actors', {error: err}) } } } diff --git a/src/state/models/feeds/notifications.ts b/src/state/models/feeds/notifications.ts index 34f5d4add..a834b543a 100644 --- a/src/state/models/feeds/notifications.ts +++ b/src/state/models/feeds/notifications.ts @@ -220,7 +220,7 @@ export class NotificationsFeedItemModel { } this.rootStore.log.warn( 'app.bsky.notifications.list served an unsupported record type', - v, + {record: v}, ) } @@ -401,7 +401,9 @@ export class NotificationsFeedModel { this._setQueued(this._filterNotifications(queueModels)) this._countUnread() } catch (e) { - this.rootStore.log.error('NotificationsModel:syncQueue failed', {e}) + this.rootStore.log.error('NotificationsModel:syncQueue failed', { + error: e, + }) } finally { this.lock.release() } @@ -481,7 +483,9 @@ export class NotificationsFeedModel { this.lastSync ? this.lastSync.toISOString() : undefined, ) } catch (e: any) { - this.rootStore.log.warn('Failed to update notifications read state', e) + this.rootStore.log.warn('Failed to update notifications read state', { + error: e, + }) } } @@ -501,13 +505,12 @@ export class NotificationsFeedModel { this.error = cleanError(error) this.loadMoreError = cleanError(loadMoreError) if (error) { - this.rootStore.log.error('Failed to fetch notifications', error) + this.rootStore.log.error('Failed to fetch notifications', {error}) } if (loadMoreError) { - this.rootStore.log.error( - 'Failed to load more notifications', - loadMoreError, - ) + this.rootStore.log.error('Failed to load more notifications', { + error: loadMoreError, + }) } } diff --git a/src/state/models/feeds/post.ts b/src/state/models/feeds/post.ts index d46cced75..be3417104 100644 --- a/src/state/models/feeds/post.ts +++ b/src/state/models/feeds/post.ts @@ -42,17 +42,16 @@ export class PostsFeedItemModel { } else { this.postRecord = undefined this.richText = undefined - rootStore.log.warn( - 'Received an invalid app.bsky.feed.post record', - valid.error, - ) + rootStore.log.warn('Received an invalid app.bsky.feed.post record', { + error: valid.error, + }) } } else { this.postRecord = undefined this.richText = undefined rootStore.log.warn( 'app.bsky.feed.getTimeline or app.bsky.feed.getAuthorFeed served an unexpected record type', - this.post.record, + {record: this.post.record}, ) } this.reply = v.reply @@ -133,7 +132,7 @@ export class PostsFeedItemModel { track('Post:Like') } } catch (error) { - this.rootStore.log.error('Failed to toggle like', error) + this.rootStore.log.error('Failed to toggle like', {error}) } } @@ -168,7 +167,7 @@ export class PostsFeedItemModel { track('Post:Repost') } } catch (error) { - this.rootStore.log.error('Failed to toggle repost', error) + this.rootStore.log.error('Failed to toggle repost', {error}) } } @@ -182,7 +181,7 @@ export class PostsFeedItemModel { track('Post:ThreadMute') } } catch (error) { - this.rootStore.log.error('Failed to toggle thread mute', error) + this.rootStore.log.error('Failed to toggle thread mute', {error}) } } @@ -191,7 +190,7 @@ export class PostsFeedItemModel { await this.rootStore.agent.deletePost(this.post.uri) this.rootStore.emitPostDeleted(this.post.uri) } catch (error) { - this.rootStore.log.error('Failed to delete post', error) + this.rootStore.log.error('Failed to delete post', {error}) } finally { track('Post:Delete') } diff --git a/src/state/models/feeds/posts.ts b/src/state/models/feeds/posts.ts index 3c580aca9..5c10ae4c7 100644 --- a/src/state/models/feeds/posts.ts +++ b/src/state/models/feeds/posts.ts @@ -324,13 +324,12 @@ export class PostsFeedModel { this.knownError = detectKnownError(this.feedType, error) this.loadMoreError = cleanError(loadMoreError) if (error) { - this.rootStore.log.error('Posts feed request failed', error) + this.rootStore.log.error('Posts feed request failed', {error}) } if (loadMoreError) { - this.rootStore.log.error( - 'Posts feed load-more request failed', - loadMoreError, - ) + this.rootStore.log.error('Posts feed load-more request failed', { + error: loadMoreError, + }) } } diff --git a/src/state/models/invited-users.ts b/src/state/models/invited-users.ts index cd3667062..995c4bfb5 100644 --- a/src/state/models/invited-users.ts +++ b/src/state/models/invited-users.ts @@ -63,10 +63,9 @@ export class InvitedUsers { }) this.rootStore.me.follows.hydrateMany(this.profiles) } catch (e) { - this.rootStore.log.error( - 'Failed to fetch profiles for invited users', - e, - ) + this.rootStore.log.error('Failed to fetch profiles for invited users', { + error: e, + }) } } } diff --git a/src/state/models/lists/actor-feeds.ts b/src/state/models/lists/actor-feeds.ts index d2bd7680b..65da765f1 100644 --- a/src/state/models/lists/actor-feeds.ts +++ b/src/state/models/lists/actor-feeds.ts @@ -98,7 +98,7 @@ export class ActorFeedsModel { this.hasLoaded = true this.error = cleanError(err) if (err) { - this.rootStore.log.error('Failed to fetch user followers', err) + this.rootStore.log.error('Failed to fetch user followers', {error: err}) } } diff --git a/src/state/models/lists/blocked-accounts.ts b/src/state/models/lists/blocked-accounts.ts index 20eef8aff..b4495b543 100644 --- a/src/state/models/lists/blocked-accounts.ts +++ b/src/state/models/lists/blocked-accounts.ts @@ -86,7 +86,7 @@ export class BlockedAccountsModel { this.hasLoaded = true this.error = cleanError(err) if (err) { - this.rootStore.log.error('Failed to fetch user followers', err) + this.rootStore.log.error('Failed to fetch user followers', {error: err}) } } diff --git a/src/state/models/lists/likes.ts b/src/state/models/lists/likes.ts index dd3cf18a3..61e480e19 100644 --- a/src/state/models/lists/likes.ts +++ b/src/state/models/lists/likes.ts @@ -97,7 +97,7 @@ export class LikesModel { this.hasLoaded = true this.error = cleanError(err) if (err) { - this.rootStore.log.error('Failed to fetch likes', err) + this.rootStore.log.error('Failed to fetch likes', {error: err}) } } diff --git a/src/state/models/lists/lists-list.ts b/src/state/models/lists/lists-list.ts index 42638757a..7415d06d7 100644 --- a/src/state/models/lists/lists-list.ts +++ b/src/state/models/lists/lists-list.ts @@ -204,10 +204,12 @@ export class ListsListModel { this.error = cleanError(err) this.loadMoreError = cleanError(loadMoreErr) if (err) { - this.rootStore.log.error('Failed to fetch user lists', err) + this.rootStore.log.error('Failed to fetch user lists', {error: err}) } if (loadMoreErr) { - this.rootStore.log.error('Failed to fetch user lists', loadMoreErr) + this.rootStore.log.error('Failed to fetch user lists', { + error: loadMoreErr, + }) } } diff --git a/src/state/models/lists/muted-accounts.ts b/src/state/models/lists/muted-accounts.ts index 9c3e1157b..bc9e53e5c 100644 --- a/src/state/models/lists/muted-accounts.ts +++ b/src/state/models/lists/muted-accounts.ts @@ -86,7 +86,7 @@ export class MutedAccountsModel { this.hasLoaded = true this.error = cleanError(err) if (err) { - this.rootStore.log.error('Failed to fetch user followers', err) + this.rootStore.log.error('Failed to fetch user followers', {error: err}) } } diff --git a/src/state/models/lists/reposted-by.ts b/src/state/models/lists/reposted-by.ts index 5d4fc107d..fe639fd0e 100644 --- a/src/state/models/lists/reposted-by.ts +++ b/src/state/models/lists/reposted-by.ts @@ -100,7 +100,7 @@ export class RepostedByModel { this.hasLoaded = true this.error = cleanError(err) if (err) { - this.rootStore.log.error('Failed to fetch reposted by view', err) + this.rootStore.log.error('Failed to fetch reposted by view', {error: err}) } } diff --git a/src/state/models/lists/user-followers.ts b/src/state/models/lists/user-followers.ts index 1f817c33c..d76ecce1a 100644 --- a/src/state/models/lists/user-followers.ts +++ b/src/state/models/lists/user-followers.ts @@ -99,7 +99,7 @@ export class UserFollowersModel { this.hasLoaded = true this.error = cleanError(err) if (err) { - this.rootStore.log.error('Failed to fetch user followers', err) + this.rootStore.log.error('Failed to fetch user followers', {error: err}) } } diff --git a/src/state/models/me.ts b/src/state/models/me.ts index e7baf5bf2..14b2ef843 100644 --- a/src/state/models/me.ts +++ b/src/state/models/me.ts @@ -110,13 +110,17 @@ export class MeModel { await this.fetchProfile() this.mainFeed.clear() /* dont await */ this.mainFeed.setup().catch(e => { - this.rootStore.log.error('Failed to setup main feed model', e) + this.rootStore.log.error('Failed to setup main feed model', {error: e}) }) /* dont await */ this.notifications.setup().catch(e => { - this.rootStore.log.error('Failed to setup notifications model', e) + this.rootStore.log.error('Failed to setup notifications model', { + error: e, + }) }) /* dont await */ this.notifications.setup().catch(e => { - this.rootStore.log.error('Failed to setup notifications model', e) + this.rootStore.log.error('Failed to setup notifications model', { + error: e, + }) }) this.myFeeds.clear() /* dont await */ this.myFeeds.saved.refresh() @@ -184,7 +188,9 @@ export class MeModel { }) }) } catch (e) { - this.rootStore.log.error('Failed to fetch user invite codes', e) + this.rootStore.log.error('Failed to fetch user invite codes', { + error: e, + }) } await this.rootStore.invitedUsers.fetch(this.invites) } @@ -199,7 +205,9 @@ export class MeModel { this.appPasswords = res.data.passwords }) } catch (e) { - this.rootStore.log.error('Failed to fetch user app passwords', e) + this.rootStore.log.error('Failed to fetch user app passwords', { + error: e, + }) } } } @@ -220,7 +228,7 @@ export class MeModel { }) return res.data } catch (e) { - this.rootStore.log.error('Failed to create app password', e) + this.rootStore.log.error('Failed to create app password', {error: e}) } } } @@ -235,7 +243,7 @@ export class MeModel { this.appPasswords = this.appPasswords.filter(p => p.name !== name) }) } catch (e) { - this.rootStore.log.error('Failed to delete app password', e) + this.rootStore.log.error('Failed to delete app password', {error: e}) } } } diff --git a/src/state/models/media/image.ts b/src/state/models/media/image.ts index c26f9b87c..4ca0b47c6 100644 --- a/src/state/models/media/image.ts +++ b/src/state/models/media/image.ts @@ -188,7 +188,7 @@ export class ImageModel implements Omit<RNImage, 'size'> { this.cropped = cropped }) } catch (err) { - this.rootStore.log.error('Failed to crop photo', err) + this.rootStore.log.error('Failed to crop photo', {error: err}) } } diff --git a/src/state/models/root-store.ts b/src/state/models/root-store.ts index 363a81c0f..621c87c11 100644 --- a/src/state/models/root-store.ts +++ b/src/state/models/root-store.ts @@ -8,7 +8,6 @@ import {createContext, useContext} from 'react' import {DeviceEventEmitter, EmitterSubscription} from 'react-native' import {z} from 'zod' import {isObj, hasProp} from 'lib/type-guards' -import {LogModel} from './log' import {SessionModel} from './session' import {ShellUiModel} from './ui/shell' import {HandleResolutionsCache} from './cache/handle-resolutions' @@ -23,6 +22,7 @@ import {ImageSizesCache} from './cache/image-sizes' import {MutedThreads} from './muted-threads' import {Reminders} from './ui/reminders' import {reset as resetNavigation} from '../../Navigation' +import {logger} from '#/logger' // TEMPORARY (APP-700) // remove after backend testing finishes @@ -41,7 +41,7 @@ export type AppInfo = z.infer<typeof appInfo> export class RootStoreModel { agent: BskyAgent appInfo?: AppInfo - log = new LogModel() + log = logger session = new SessionModel(this) shell = new ShellUiModel(this) preferences = new PreferencesModel(this) @@ -130,7 +130,7 @@ export class RootStoreModel { }) this.updateSessionState() } catch (e: any) { - this.log.warn('Failed to initialize session', e) + this.log.warn('Failed to initialize session', {error: e}) } } @@ -184,7 +184,7 @@ export class RootStoreModel { await this.me.updateIfNeeded() await this.preferences.sync() } catch (e: any) { - this.log.error('Failed to fetch latest state', e) + this.log.error('Failed to fetch latest state', {error: e}) } } diff --git a/src/state/models/ui/create-account.ts b/src/state/models/ui/create-account.ts index 9f11a9b31..3bd39ba76 100644 --- a/src/state/models/ui/create-account.ts +++ b/src/state/models/ui/create-account.ts @@ -78,7 +78,7 @@ export class CreateAccountModel { } catch (err: any) { this.rootStore.log.warn( `Failed to fetch service description for ${this.serviceUrl}`, - err, + {error: err}, ) this.setError( 'Unable to contact your service. Please check your Internet connection.', @@ -127,7 +127,7 @@ export class CreateAccountModel { errMsg = 'Invite code not accepted. Check that you input it correctly and try again.' } - this.rootStore.log.error('Failed to create account', e) + this.rootStore.log.error('Failed to create account', {error: e}) this.setIsProcessing(false) this.setError(cleanError(errMsg)) throw e diff --git a/src/state/models/ui/profile.ts b/src/state/models/ui/profile.ts index 8525426bf..47a99a8fc 100644 --- a/src/state/models/ui/profile.ts +++ b/src/state/models/ui/profile.ts @@ -223,10 +223,14 @@ export class ProfileUiModel { await Promise.all([ this.profile .setup() - .catch(err => this.rootStore.log.error('Failed to fetch profile', err)), + .catch(err => + this.rootStore.log.error('Failed to fetch profile', {error: err}), + ), this.feed .setup() - .catch(err => this.rootStore.log.error('Failed to fetch feed', err)), + .catch(err => + this.rootStore.log.error('Failed to fetch feed', {error: err}), + ), ]) runInAction(() => { this.isAuthenticatedUser = @@ -237,7 +241,9 @@ export class ProfileUiModel { this.lists.source = this.profile.did this.lists .loadMore() - .catch(err => this.rootStore.log.error('Failed to fetch lists', err)) + .catch(err => + this.rootStore.log.error('Failed to fetch lists', {error: err}), + ) } async refresh() { diff --git a/src/state/models/ui/saved-feeds.ts b/src/state/models/ui/saved-feeds.ts index 667bc03a3..72055abeb 100644 --- a/src/state/models/ui/saved-feeds.ts +++ b/src/state/models/ui/saved-feeds.ts @@ -126,7 +126,7 @@ export class SavedFeedsModel { this.hasLoaded = true this.error = cleanError(err) if (err) { - this.rootStore.log.error('Failed to fetch user feeds', err) + this.rootStore.log.error('Failed to fetch user feeds', {err}) } } |