Fix immediate TS errors

zio/stable
Eric Bailey 2023-11-04 12:42:27 -05:00
parent 5fd41ad5a2
commit df0dcf32f9
19 changed files with 81 additions and 71 deletions

View File

@ -178,10 +178,9 @@ export async function post(store: RootStoreModel, opts: PostOpts) {
) {
encoding = 'image/jpeg'
} else {
store.log.warn(
'Unexpected image format for thumbnail, skipping',
opts.extLink.localThumb.path,
)
store.log.warn('Unexpected image format for thumbnail, skipping', {
thumbnail: opts.extLink.localThumb.path,
})
}
if (encoding) {
const thumbUploadRes = await uploadBlob(

View File

@ -34,18 +34,18 @@ export function useOTAUpdate() {
// show a popup modal
showUpdatePopup()
} catch (e) {
console.error('useOTAUpdate: Error while checking for update', e)
store.log.error('useOTAUpdate: Error while checking for update', e)
store.log.error('useOTAUpdate: Error while checking for update', {
error: e,
})
}
}, [showUpdatePopup, store.log])
const updateEventListener = useCallback(
(event: Updates.UpdateEvent) => {
store.log.debug('useOTAUpdate: Listening for update...')
if (event.type === Updates.UpdateEventType.ERROR) {
store.log.error(
'useOTAUpdate: Error while listening for update',
event.message,
)
store.log.error('useOTAUpdate: Error while listening for update', {
message: event.message,
})
} else if (event.type === Updates.UpdateEventType.NO_UPDATE_AVAILABLE) {
// Handle no update available
// do nothing

View File

@ -30,18 +30,18 @@ export function init(store: RootStoreModel) {
appId: 'xyz.blueskyweb.app',
})
store.log.debug('Notifications: Sent push token (init)', {
type: token.type,
tokenType: token.type,
token: token.data,
})
} catch (error) {
store.log.error('Notifications: Failed to set push token', error)
store.log.error('Notifications: Failed to set push token', {error})
}
}
// listens for new changes to the push token
// In rare situations, a push token may be changed by the push notification service while the app is running. When a token is rolled, the old one becomes invalid and sending notifications to it will fail. A push token listener will let you handle this situation gracefully by registering the new token with your backend right away.
Notifications.addPushTokenListener(async ({data: t, type}) => {
store.log.debug('Notifications: Push token changed', {t, type})
store.log.debug('Notifications: Push token changed', {t, tokenType: type})
if (t) {
try {
await store.agent.api.app.bsky.notification.registerPush({
@ -51,11 +51,11 @@ export function init(store: RootStoreModel) {
appId: 'xyz.blueskyweb.app',
})
store.log.debug('Notifications: Sent push token (event)', {
type,
tokenType: type,
token: t,
})
} catch (error) {
store.log.error('Notifications: Failed to set push token', error)
store.log.error('Notifications: Failed to set push token', {error})
}
}
})
@ -63,7 +63,7 @@ export function init(store: RootStoreModel) {
// handle notifications that are received, both in the foreground or background
Notifications.addNotificationReceivedListener(event => {
store.log.debug('Notifications: received', event)
store.log.debug('Notifications: received', {event})
if (event.request.trigger.type === 'push') {
// refresh notifications in the background
store.me.notifications.syncQueue()
@ -84,10 +84,9 @@ export function init(store: RootStoreModel) {
// handle notifications that are tapped on
const sub = Notifications.addNotificationResponseReceivedListener(
response => {
store.log.debug(
'Notifications: response received',
response.actionIdentifier,
)
store.log.debug('Notifications: response received', {
actionIdentifier: response.actionIdentifier,
})
if (
response.actionIdentifier === Notifications.DEFAULT_ACTION_IDENTIFIER
) {

View File

@ -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')
}

View File

@ -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,
})
}
}

View File

@ -220,7 +220,7 @@ export class NotificationsFeedItemModel {
}
this.rootStore.log.warn(
'app.bsky.notifications.list served an unsupported record type',
v,
{record: v},
)
}

View File

@ -42,10 +42,9 @@ 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
@ -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')
}

View File

@ -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,
})
}
}
}

View File

@ -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})
}
}
}

View File

@ -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})
}
}

View File

@ -94,7 +94,7 @@ export const ListItems = observer(function ListItemsImpl({
try {
await list.refresh()
} catch (err) {
list.rootStore.log.error('Failed to refresh lists', err)
list.rootStore.log.error('Failed to refresh lists', {error: err})
}
setIsRefreshing(false)
}, [list, track, setIsRefreshing])
@ -104,7 +104,7 @@ export const ListItems = observer(function ListItemsImpl({
try {
await list.loadMore()
} catch (err) {
list.rootStore.log.error('Failed to load more lists', err)
list.rootStore.log.error('Failed to load more lists', {error: err})
}
}, [list, track])

View File

@ -78,7 +78,7 @@ export const ListsList = observer(function ListsListImpl({
try {
await listsList.refresh()
} catch (err) {
listsList.rootStore.log.error('Failed to refresh lists', err)
listsList.rootStore.log.error('Failed to refresh lists', {error: err})
}
setIsRefreshing(false)
}, [listsList, track, setIsRefreshing])
@ -88,7 +88,7 @@ export const ListsList = observer(function ListsListImpl({
try {
await listsList.loadMore()
} catch (err) {
listsList.rootStore.log.error('Failed to load more lists', err)
listsList.rootStore.log.error('Failed to load more lists', {error: err})
}
}, [listsList, track])

View File

@ -61,7 +61,9 @@ export const Feed = observer(function Feed({
setIsPTRing(true)
await view.refresh()
} catch (err) {
view.rootStore.log.error('Failed to refresh notifications feed', err)
view.rootStore.log.error('Failed to refresh notifications feed', {
error: err,
})
} finally {
setIsPTRing(false)
}
@ -71,7 +73,9 @@ export const Feed = observer(function Feed({
try {
await view.loadMore()
} catch (err) {
view.rootStore.log.error('Failed to load more notifications', err)
view.rootStore.log.error('Failed to load more notifications', {
error: err,
})
}
}, [view])

View File

@ -119,7 +119,7 @@ export const PostThread = observer(function PostThread({
try {
view?.refresh()
} catch (err) {
view.rootStore.log.error('Failed to refresh posts thread', err)
view.rootStore.log.error('Failed to refresh posts thread', {error: err})
}
setIsRefreshing(false)
}, [view, setIsRefreshing])

View File

@ -111,13 +111,13 @@ export const PostThreadItem = observer(function PostThreadItem({
const onPressToggleRepost = React.useCallback(() => {
return item
.toggleRepost()
.catch(e => store.log.error('Failed to toggle repost', e))
.catch(e => store.log.error('Failed to toggle repost', {error: e}))
}, [item, store])
const onPressToggleLike = React.useCallback(() => {
return item
.toggleLike()
.catch(e => store.log.error('Failed to toggle like', e))
.catch(e => store.log.error('Failed to toggle like', {error: e}))
}, [item, store])
const onCopyPostText = React.useCallback(() => {
@ -138,7 +138,7 @@ export const PostThreadItem = observer(function PostThreadItem({
Toast.show('You will now receive notifications for this thread')
}
} catch (e) {
store.log.error('Failed to toggle thread mute', e)
store.log.error('Failed to toggle thread mute', {error: e})
}
}, [item, store])
@ -149,7 +149,7 @@ export const PostThreadItem = observer(function PostThreadItem({
Toast.show('Post deleted')
},
e => {
store.log.error('Failed to delete post', e)
store.log.error('Failed to delete post', {error: e})
Toast.show('Failed to delete post, please try again')
},
)

View File

@ -142,13 +142,13 @@ const PostLoaded = observer(function PostLoadedImpl({
const onPressToggleRepost = React.useCallback(() => {
return item
.toggleRepost()
.catch(e => store.log.error('Failed to toggle repost', e))
.catch(e => store.log.error('Failed to toggle repost', {error: e}))
}, [item, store])
const onPressToggleLike = React.useCallback(() => {
return item
.toggleLike()
.catch(e => store.log.error('Failed to toggle like', e))
.catch(e => store.log.error('Failed to toggle like', {error: e}))
}, [item, store])
const onCopyPostText = React.useCallback(() => {
@ -169,7 +169,7 @@ const PostLoaded = observer(function PostLoadedImpl({
Toast.show('You will now receive notifications for this thread')
}
} catch (e) {
store.log.error('Failed to toggle thread mute', e)
store.log.error('Failed to toggle thread mute', {error: e})
}
}, [item, store])
@ -180,7 +180,7 @@ const PostLoaded = observer(function PostLoadedImpl({
Toast.show('Post deleted')
},
e => {
store.log.error('Failed to delete post', e)
store.log.error('Failed to delete post', {error: e})
Toast.show('Failed to delete post, please try again')
},
)

View File

@ -92,7 +92,7 @@ export const Feed = observer(function Feed({
try {
await feed.refresh()
} catch (err) {
feed.rootStore.log.error('Failed to refresh posts feed', err)
feed.rootStore.log.error('Failed to refresh posts feed', {error: err})
}
setIsRefreshing(false)
}, [feed, track, setIsRefreshing])
@ -104,7 +104,7 @@ export const Feed = observer(function Feed({
try {
await feed.loadMore()
} catch (err) {
feed.rootStore.log.error('Failed to load more posts', err)
feed.rootStore.log.error('Failed to load more posts', {error: err})
}
}, [feed, track])

View File

@ -94,14 +94,14 @@ export const FeedItem = observer(function FeedItemImpl({
track('FeedItem:PostRepost')
return item
.toggleRepost()
.catch(e => store.log.error('Failed to toggle repost', e))
.catch(e => store.log.error('Failed to toggle repost', {error: e}))
}, [track, item, store])
const onPressToggleLike = React.useCallback(() => {
track('FeedItem:PostLike')
return item
.toggleLike()
.catch(e => store.log.error('Failed to toggle like', e))
.catch(e => store.log.error('Failed to toggle like', {error: e}))
}, [track, item, store])
const onCopyPostText = React.useCallback(() => {
@ -123,7 +123,7 @@ export const FeedItem = observer(function FeedItemImpl({
Toast.show('You will now receive notifications for this thread')
}
} catch (e) {
store.log.error('Failed to toggle thread mute', e)
store.log.error('Failed to toggle thread mute', {error: e})
}
}, [track, item, store])
@ -135,7 +135,7 @@ export const FeedItem = observer(function FeedItemImpl({
Toast.show('Post deleted')
},
e => {
store.log.error('Failed to delete post', e)
store.log.error('Failed to delete post', {error: e})
Toast.show('Failed to delete post, please try again')
},
)

View File

@ -38,7 +38,7 @@ export const PostThreadScreen = withAuthRequired(
InteractionManager.runAfterInteractions(() => {
if (!view.hasLoaded && !view.isLoading) {
view.setup().catch(err => {
store.log.error('Failed to fetch thread', err)
store.log.error('Failed to fetch thread', {error: err})
})
}
})