Molunerfinn/PicGo · error

result.error (dynamic message propagated from RPC failure)

Error message

result.error (dynamic message propagated from RPC failure)

What it means

fetchCloudAlbumStats throws Error(result.error) when the PICGO_CLOUD_ALBUM_GET_STATS RPC invoked via cloudAlbumAdapter.getStats() returns success:false. The library uses this pattern to convert RPC failure envelopes into thrown errors so TanStack Query records the fetch as failed. The message is the dynamic error text produced by the main-process RPC handler, so its content is not fixed.

Source

Thrown at src/renderer/queries/picgo-cloud-album-stats.ts:13

import { useQuery } from '@tanstack/react-query'
import type { CloudAlbumStatsResponse } from '#/types/cloudAlbum'
import { cloudAlbumAdapter } from '@/adapters/cloud-album'
import { rendererQueryClient } from './query-client'

export const PicGoCloudAlbumStatsQueryKeys = {
  stats: ['picgo-cloud-album', 'stats'] as const
}

async function fetchCloudAlbumStats (): Promise<CloudAlbumStatsResponse> {
  const result = await cloudAlbumAdapter.getStats()
  if (!result.success) {
    throw new Error(result.error)
  }
  return result.data
}

export function useCloudAlbumStatsQuery (options?: { enabled?: boolean }) {
  return useQuery({
    queryKey: PicGoCloudAlbumStatsQueryKeys.stats,
    queryFn: fetchCloudAlbumStats,
    refetchOnWindowFocus: true,
    enabled: options?.enabled ?? true
  })
}

export async function invalidateCloudAlbumStatsQuery () {
  await rendererQueryClient.invalidateQueries({
    queryKey: PicGoCloudAlbumStatsQueryKeys.stats
  })
}

View on GitHub (pinned to 07ec7068a5)

Solutions

  1. Check the error message in the query (query.error.message) — it names the actual RPC failure (auth, network, or plan code).
  2. If it is auth-related, re-run the PicGo Cloud login flow (cloudAdapter.login) and invalidate the query.
  3. If it is a plan/quota code (PLAN_REQUIRED, QUOTA_EXCEEDED, GRACE_RESTRICTED), resolve it via resolveCloudErrorMessage and upgrade/renew the plan.
  4. For network errors, restore connectivity and refetch; the query key ['picgo-cloud-album','stats'] can be invalidated manually.
  5. If result.error can be undefined, the thrown Error may have an empty message — consider a fallback message like in the plugin actions pattern.

Example fix

// before
const result = await cloudAlbumAdapter.getStats()
if (!result.success) {
  throw new Error(result.error)
}
// after
const result = await cloudAlbumAdapter.getStats()
if (!result.success) {
  throw new Error(result.error || i18n.t('OPERATION_FAILED'))
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Before calling the query, check session state
const userInfo = rendererQueryClient.getQueryData<IPicGoCloudUserInfo | null>(['picgo-cloud', 'user-info'])
if (!userInfo) throw new Error('Not logged in to PicGo Cloud')

Type guard

function isRPCSuccess<T>(r: { success: boolean, data?: T, error?: string }): r is { success: true, data: T } {
  return r.success === true && r.data !== undefined
}

Try / catch

const { data, error } = useCloudAlbumStatsQuery()
// or imperatively:
try {
  const stats = await rendererQueryClient.fetchQuery({ queryKey: ['picgo-cloud-album', 'stats'], queryFn: fetchCloudAlbumStats })
} catch (e) {
  const msg = e instanceof Error ? e.message : 'Unknown error'
  toast.error(resolveCloudErrorMessage(i18n.t, undefined, undefined, msg))
}

Prevention

When it happens

Trigger: The RPC handler for cloud album stats fails: user not logged in to PicGo Cloud, expired/invalid token, network failure reaching picgo-hub, lifecycle restriction (grace/frozen/plan required, e.g. GRACE_RESTRICTED / QUOTA_EXCEEDED codes), or main-process handler throwing and serializing its error message into result.error.

Common situations: Opening the cloud album stats panel while offline or with an expired session; free-plan user triggering stats that require a paid plan; token revoked after password change; server 5xx during picgo-hub maintenance.

Related errors


AI-assisted analysis of Molunerfinn/PicGo@07ec7068a5 (2026-08-30). Data as JSON: /api/errors/5f4706183a3f15e0. Report an issue: GitHub.