Improve error logging
This commit is contained in:
parent
6885fb2b41
commit
4eabc2d65a
49 changed files with 212 additions and 188 deletions
|
@ -25,7 +25,7 @@ export async function setupState() {
|
|||
data = (await storage.load(ROOT_STATE_STORAGE_KEY)) || {}
|
||||
rootStore.hydrate(data)
|
||||
} catch (e: any) {
|
||||
rootStore.log.error('Failed to load state from storage', e.toString())
|
||||
rootStore.log.error('Failed to load state from storage', e)
|
||||
}
|
||||
|
||||
rootStore.log.debug('Initial hydrate')
|
||||
|
@ -36,7 +36,7 @@ export async function setupState() {
|
|||
return rootStore.fetchStateUpdate()
|
||||
})
|
||||
.catch((e: any) => {
|
||||
rootStore.log.warn('Failed initial connect', e.toString())
|
||||
rootStore.log.warn('Failed initial connect', e)
|
||||
})
|
||||
// @ts-ignore .on() is correct -prf
|
||||
api.sessionManager.on('session', () => {
|
||||
|
|
|
@ -126,10 +126,7 @@ export async function post(
|
|||
},
|
||||
} as AppBskyEmbedExternal.Main
|
||||
} catch (e: any) {
|
||||
store.log.warn(
|
||||
`Failed to fetch link meta for ${link.value}`,
|
||||
e.toString(),
|
||||
)
|
||||
store.log.warn(`Failed to fetch link meta for ${link.value}`, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -320,11 +320,14 @@ export class FeedModel {
|
|||
this.error = ''
|
||||
}
|
||||
|
||||
private _xIdle(err: string = '') {
|
||||
private _xIdle(err?: any) {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = cleanError(err)
|
||||
this.error = err ? cleanError(err.toString()) : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Posts feed request failed', err)
|
||||
}
|
||||
}
|
||||
|
||||
// loader functions
|
||||
|
@ -352,7 +355,7 @@ export class FeedModel {
|
|||
await this._replaceAll(res)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e.toString())
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -363,7 +366,7 @@ export class FeedModel {
|
|||
await this._prependAll(res)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e.toString())
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -380,7 +383,7 @@ export class FeedModel {
|
|||
await this._appendAll(res)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(`Failed to load feed: ${e.toString()}`)
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -408,7 +411,7 @@ export class FeedModel {
|
|||
} while (numToFetch > 0)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(`Failed to update feed: ${e.toString()}`)
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,11 +80,14 @@ export class GetAssertionsView {
|
|||
this.error = ''
|
||||
}
|
||||
|
||||
private _xIdle(err: string = '') {
|
||||
private _xIdle(err?: any) {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err
|
||||
this.error = err ? err.toString() : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch assertions', err)
|
||||
}
|
||||
}
|
||||
|
||||
// loader functions
|
||||
|
@ -99,7 +102,7 @@ export class GetAssertionsView {
|
|||
this._replaceAll(res)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e.toString())
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import {makeAutoObservable} from 'mobx'
|
||||
import {XRPCError, XRPCInvalidResponseError} from '@atproto/xrpc'
|
||||
import {isObj, hasProp} from '../lib/type-guards'
|
||||
|
||||
interface LogEntry {
|
||||
|
@ -51,9 +52,7 @@ export class LogModel {
|
|||
}
|
||||
|
||||
debug(summary: string, details?: any) {
|
||||
if (details && typeof details !== 'string') {
|
||||
details = JSON.stringify(details, null, 2)
|
||||
}
|
||||
details = detailsToStr(details)
|
||||
console.debug(summary, details || '')
|
||||
this.add({
|
||||
id: genId(),
|
||||
|
@ -65,10 +64,8 @@ export class LogModel {
|
|||
}
|
||||
|
||||
warn(summary: string, details?: any) {
|
||||
if (details && typeof details !== 'string') {
|
||||
details = JSON.stringify(details, null, 2)
|
||||
}
|
||||
console.warn(summary, details || '')
|
||||
details = detailsToStr(details)
|
||||
console.debug(summary, details || '')
|
||||
this.add({
|
||||
id: genId(),
|
||||
type: 'warn',
|
||||
|
@ -79,10 +76,8 @@ export class LogModel {
|
|||
}
|
||||
|
||||
error(summary: string, details?: any) {
|
||||
if (details && typeof details !== 'string') {
|
||||
details = JSON.stringify(details, null, 2)
|
||||
}
|
||||
console.error(summary, details || '')
|
||||
details = detailsToStr(details)
|
||||
console.debug(summary, details || '')
|
||||
this.add({
|
||||
id: genId(),
|
||||
type: 'error',
|
||||
|
@ -92,3 +87,25 @@ export class LogModel {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
function detailsToStr(details?: any) {
|
||||
if (details && typeof details !== 'string') {
|
||||
if (
|
||||
details instanceof XRPCInvalidResponseError ||
|
||||
details.constructor.name === 'XRPCInvalidResponseError'
|
||||
) {
|
||||
return `The server gave an ill-formatted response.\nMethod: ${
|
||||
details.lexiconNsid
|
||||
}.\nError: ${details.validationError.toString()}`
|
||||
} else if (
|
||||
details instanceof XRPCError ||
|
||||
details.constructor.name === 'XRPCError'
|
||||
) {
|
||||
return `An XRPC error occurred.\nStatus: ${details.status}\nError: ${details.error}\nMessage: ${details.message}`
|
||||
} else if (details instanceof Error) {
|
||||
return details.toString()
|
||||
}
|
||||
return JSON.stringify(details, null, 2)
|
||||
}
|
||||
return details
|
||||
}
|
||||
|
|
|
@ -104,22 +104,13 @@ export class MeModel {
|
|||
})
|
||||
await Promise.all([
|
||||
this.memberships?.setup().catch(e => {
|
||||
this.rootStore.log.error(
|
||||
'Failed to setup memberships model',
|
||||
e.toString(),
|
||||
)
|
||||
this.rootStore.log.error('Failed to setup memberships model', e)
|
||||
}),
|
||||
this.mainFeed.setup().catch(e => {
|
||||
this.rootStore.log.error(
|
||||
'Failed to setup main feed model',
|
||||
e.toString(),
|
||||
)
|
||||
this.rootStore.log.error('Failed to setup main feed model', e)
|
||||
}),
|
||||
this.notifications.setup().catch(e => {
|
||||
this.rootStore.log.error(
|
||||
'Failed to setup notifications model',
|
||||
e.toString(),
|
||||
)
|
||||
this.rootStore.log.error('Failed to setup notifications model', e)
|
||||
}),
|
||||
])
|
||||
} else {
|
||||
|
|
|
@ -104,11 +104,14 @@ export class MembersViewModel {
|
|||
this.error = ''
|
||||
}
|
||||
|
||||
private _xIdle(err: string = '') {
|
||||
private _xIdle(err?: any) {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err
|
||||
this.error = err ? err.toString() : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch members', err)
|
||||
}
|
||||
}
|
||||
|
||||
// loader functions
|
||||
|
@ -123,7 +126,7 @@ export class MembersViewModel {
|
|||
this._replaceAll(res)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(`Failed to load feed: ${e.toString()}`)
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -82,11 +82,14 @@ export class MembershipsViewModel {
|
|||
this.error = ''
|
||||
}
|
||||
|
||||
private _xIdle(err: string = '') {
|
||||
private _xIdle(err?: any) {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err
|
||||
this.error = err ? err.toString() : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch memberships', err)
|
||||
}
|
||||
}
|
||||
|
||||
// loader functions
|
||||
|
@ -101,7 +104,7 @@ export class MembershipsViewModel {
|
|||
this._replaceAll(res)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(`Failed to load feed: ${e.toString()}`)
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ export class NotificationsViewItemModel implements GroupedNotification {
|
|||
await this.additionalPost.setup().catch(e => {
|
||||
this.rootStore.log.error(
|
||||
'Failed to load post needed by notification',
|
||||
e.toString(),
|
||||
e,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
@ -266,10 +266,7 @@ export class NotificationsViewModel {
|
|||
})
|
||||
this.rootStore.me.clearNotificationCount()
|
||||
} catch (e: any) {
|
||||
this.rootStore.log.warn(
|
||||
'Failed to update notifications read state',
|
||||
e.toString(),
|
||||
)
|
||||
this.rootStore.log.warn('Failed to update notifications read state', e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,11 +279,15 @@ export class NotificationsViewModel {
|
|||
this.error = ''
|
||||
}
|
||||
|
||||
private _xIdle(err: string = '') {
|
||||
private _xIdle(err?: any) {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = cleanError(err)
|
||||
this.error = err ? cleanError(err) : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch notifications', err)
|
||||
}
|
||||
}
|
||||
|
||||
// loader functions
|
||||
|
@ -314,7 +315,7 @@ export class NotificationsViewModel {
|
|||
await this._replaceAll(res)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(`Failed to load notifications: ${e.toString()}`)
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,7 +333,7 @@ export class NotificationsViewModel {
|
|||
await this._appendAll(res)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(`Failed to load notifications: ${e.toString()}`)
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,7 +360,7 @@ export class NotificationsViewModel {
|
|||
} while (numToFetch > 0)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(`Failed to update notifications: ${e.toString()}`)
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -386,7 +387,7 @@ export class NotificationsViewModel {
|
|||
await Promise.all(promises).catch(e => {
|
||||
this.rootStore.log.error(
|
||||
'Uncaught failure during notifications-view _appendAll()',
|
||||
e.toString(),
|
||||
e,
|
||||
)
|
||||
})
|
||||
runInAction(() => {
|
||||
|
|
|
@ -236,11 +236,14 @@ export class PostThreadViewModel {
|
|||
this.notFound = false
|
||||
}
|
||||
|
||||
private _xIdle(err: any = undefined) {
|
||||
private _xIdle(err?: any) {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err ? err.toString() : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch assertions', err)
|
||||
}
|
||||
this.notFound = err instanceof GetPostThread.NotFoundError
|
||||
}
|
||||
|
||||
|
|
|
@ -63,10 +63,14 @@ export class PostModel implements RemoveIndex<Post.Record> {
|
|||
this.error = ''
|
||||
}
|
||||
|
||||
private _xIdle(err: string = '') {
|
||||
private _xIdle(err?: any) {
|
||||
this.isLoading = false
|
||||
this.hasLoaded = true
|
||||
this.error = cleanError(err)
|
||||
this.error = err ? cleanError(err) : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch post', err)
|
||||
}
|
||||
}
|
||||
|
||||
// loader functions
|
||||
|
@ -87,7 +91,7 @@ export class PostModel implements RemoveIndex<Post.Record> {
|
|||
this._replaceAll(res.value)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e.toString())
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -114,28 +114,20 @@ export class ProfileUiModel {
|
|||
await Promise.all([
|
||||
this.profile
|
||||
.setup()
|
||||
.catch(err =>
|
||||
this.rootStore.log.error('Failed to fetch profile', err.toString()),
|
||||
),
|
||||
.catch(err => this.rootStore.log.error('Failed to fetch profile', err)),
|
||||
this.feed
|
||||
.setup()
|
||||
.catch(err =>
|
||||
this.rootStore.log.error('Failed to fetch feed', err.toString()),
|
||||
),
|
||||
.catch(err => this.rootStore.log.error('Failed to fetch feed', err)),
|
||||
])
|
||||
if (this.isUser) {
|
||||
await this.memberships
|
||||
.setup()
|
||||
.catch(err =>
|
||||
this.rootStore.log.error('Failed to fetch members', err.toString()),
|
||||
)
|
||||
.catch(err => this.rootStore.log.error('Failed to fetch members', err))
|
||||
}
|
||||
if (this.isScene) {
|
||||
await this.members
|
||||
.setup()
|
||||
.catch(err =>
|
||||
this.rootStore.log.error('Failed to fetch members', err.toString()),
|
||||
)
|
||||
.catch(err => this.rootStore.log.error('Failed to fetch members', err))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -178,11 +178,14 @@ export class ProfileViewModel {
|
|||
this.error = ''
|
||||
}
|
||||
|
||||
private _xIdle(err: string = '') {
|
||||
private _xIdle(err?: any) {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err
|
||||
this.error = err ? err.toString() : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch profile', err)
|
||||
}
|
||||
}
|
||||
|
||||
// loader functions
|
||||
|
@ -198,7 +201,7 @@ export class ProfileViewModel {
|
|||
this._replaceAll(res)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e.toString())
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -94,11 +94,14 @@ export class RepostedByViewModel {
|
|||
this.error = ''
|
||||
}
|
||||
|
||||
private _xIdle(err: string = '') {
|
||||
private _xIdle(err?: any) {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err
|
||||
this.error = err ? err.toString() : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch reposted by view', err)
|
||||
}
|
||||
}
|
||||
|
||||
// loader functions
|
||||
|
@ -127,7 +130,7 @@ export class RepostedByViewModel {
|
|||
this._replaceAll(res)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(`Failed to load feed: ${e.toString()}`)
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ export class RootStoreModel {
|
|||
if (isNetworkError(e)) {
|
||||
this.session.setOnline(false) // connection lost
|
||||
}
|
||||
this.log.error('Failed to fetch latest state', e.toString())
|
||||
this.log.error('Failed to fetch latest state', e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ export class SessionModel {
|
|||
} catch (e: any) {
|
||||
this.rootStore.log.error(
|
||||
`Invalid service URL: ${this.data.service}. Resetting session.`,
|
||||
e.toString(),
|
||||
e,
|
||||
)
|
||||
this.clear()
|
||||
return false
|
||||
|
@ -160,10 +160,7 @@ export class SessionModel {
|
|||
this.rootStore.me.clear()
|
||||
}
|
||||
this.rootStore.me.load().catch(e => {
|
||||
this.rootStore.log.error(
|
||||
'Failed to fetch local user information',
|
||||
e.toString(),
|
||||
)
|
||||
this.rootStore.log.error('Failed to fetch local user information', e)
|
||||
})
|
||||
return // success
|
||||
}
|
||||
|
@ -207,10 +204,7 @@ export class SessionModel {
|
|||
this.configureApi()
|
||||
this.setOnline(true, false)
|
||||
this.rootStore.me.load().catch(e => {
|
||||
this.rootStore.log.error(
|
||||
'Failed to fetch local user information',
|
||||
e.toString(),
|
||||
)
|
||||
this.rootStore.log.error('Failed to fetch local user information', e)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -246,10 +240,7 @@ export class SessionModel {
|
|||
this.rootStore.onboard.start()
|
||||
this.configureApi()
|
||||
this.rootStore.me.load().catch(e => {
|
||||
this.rootStore.log.error(
|
||||
'Failed to fetch local user information',
|
||||
e.toString(),
|
||||
)
|
||||
this.rootStore.log.error('Failed to fetch local user information', e)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,11 +58,14 @@ export class SuggestedActorsViewModel {
|
|||
this.error = ''
|
||||
}
|
||||
|
||||
private _xIdle(err: string = '') {
|
||||
private _xIdle(err?: any) {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err
|
||||
this.error = err ? err.toString() : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch suggested actors', err)
|
||||
}
|
||||
}
|
||||
|
||||
// loader functions
|
||||
|
@ -88,7 +91,7 @@ export class SuggestedActorsViewModel {
|
|||
)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e.toString())
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -83,11 +83,14 @@ export class SuggestedInvitesView {
|
|||
this.error = ''
|
||||
}
|
||||
|
||||
private _xIdle(err: string = '') {
|
||||
private _xIdle(err?: any) {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err
|
||||
this.error = err ? err.toString() : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch suggested invites', err)
|
||||
}
|
||||
}
|
||||
|
||||
// loader functions
|
||||
|
@ -101,7 +104,7 @@ export class SuggestedInvitesView {
|
|||
} catch (e: any) {
|
||||
this.rootStore.log.error(
|
||||
'Failed to fetch current scene members in suggested invites',
|
||||
e.toString(),
|
||||
e,
|
||||
)
|
||||
this._xIdle(
|
||||
'Failed to fetch the current scene members. Check your internet connection and try again.',
|
||||
|
@ -113,7 +116,7 @@ export class SuggestedInvitesView {
|
|||
} catch (e: any) {
|
||||
this.rootStore.log.error(
|
||||
'Failed to fetch current followers in suggested invites',
|
||||
e.toString(),
|
||||
e,
|
||||
)
|
||||
this._xIdle(
|
||||
'Failed to fetch the your current followers. Check your internet connection and try again.',
|
||||
|
|
|
@ -76,11 +76,14 @@ export class UserFollowersViewModel {
|
|||
this.error = ''
|
||||
}
|
||||
|
||||
private _xIdle(err: string = '') {
|
||||
private _xIdle(err?: any) {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err
|
||||
this.error = err ? err.toString() : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch user followers', err)
|
||||
}
|
||||
}
|
||||
|
||||
// loader functions
|
||||
|
|
|
@ -76,11 +76,14 @@ export class UserFollowsViewModel {
|
|||
this.error = ''
|
||||
}
|
||||
|
||||
private _xIdle(err: string = '') {
|
||||
private _xIdle(err?: any) {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err
|
||||
this.error = err ? err.toString() : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch user follows', err)
|
||||
}
|
||||
}
|
||||
|
||||
// loader functions
|
||||
|
|
|
@ -91,11 +91,14 @@ export class VotesViewModel {
|
|||
this.error = ''
|
||||
}
|
||||
|
||||
private _xIdle(err: string = '') {
|
||||
private _xIdle(err?: any) {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err
|
||||
this.error = err ? err.toString() : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch votes', err)
|
||||
}
|
||||
}
|
||||
|
||||
// loader functions
|
||||
|
@ -124,7 +127,7 @@ export class VotesViewModel {
|
|||
this._replaceAll(res)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(`Failed to load feed: ${e.toString()}`)
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue