{"record":{"id":"d575aeee5cb5f11c","repo":"yikart/AiToEarn","slug":"error-d575ae","errorCode":null,"errorMessage":"插件未就绪，请先授权插件权限","messagePattern":"插件未就绪，请先授权插件权限","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"project/aitoearn-web/src/store/plugin/store.ts","lineNumber":735,"sourceCode":"            console.error('同步账号失败:', result?.message)\n            return null\n          }\n        }\n        catch (error) {\n          console.error('同步账号到数据库失败:', error)\n          return null\n        }\n      },\n\n      /** 登录到指定平台 */\n      async login(platform: PluginPlatformType) {\n        const { status, platformAccounts } = get()\n\n        if (status === Status.NOT_INSTALLED)\n          throw new Error(ERROR_MESSAGES.PLUGIN_NOT_INSTALLED)\n\n        if (status !== Status.READY)\n          throw new Error(ERROR_MESSAGES.PLUGIN_NOT_READY)\n\n        try {\n          const result = await window.AIToEarnPlugin!.login(platform)\n          set({\n            platformAccounts: { ...platformAccounts, [platform]: result },\n          })\n          await methods.syncAccountToDatabase(platform)\n          return result\n        }\n        catch (error) {\n          console.error('登录失败:', error)\n          throw error\n        }\n      },\n\n      /** 发布内容到指定平台 */\n      async publish(params: PublishParams, onProgress?: ProgressCallback) {\n        const { status, publishingPlatforms, platformProgress } = get()","sourceCodeStart":717,"sourceCodeEnd":753,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-web/src/store/plugin/store.ts#L717-L753","documentation":"login(platform) also throws ERROR_MESSAGES.PLUGIN_NOT_READY ('插件未就绪，请先授权插件权限') when the status is neither NOT_INSTALLED nor READY — i.e. the extension is detected but not yet initialized/authorized (e.g. needs user grant, still connecting, or in an error state). The guard prevents calling window.AIToEarnPlugin.login on a plugin that can't service it yet.","triggerScenarios":"Calling login() while status is a non-READY intermediate/failed state: extension detected but permissions not granted, content-script handshake incomplete, or the store marked the plugin not-ready after a failed init.","commonSituations":"User clicks login immediately after page load before the plugin handshake finishes; extension permissions revoked leaving status non-ready; extension version update requiring re-authorization.","solutions":["Open the extension and grant the requested permissions, then reload and wait for status to become READY before calling login().","Subscribe to the plugin store status and only enable the login action when status === Status.READY.","If stuck non-ready, call the store's re-init/detect routine or reinstall/update the extension.","Catch the error by message and show 'authorize plugin permissions' guidance with a retry after re-checking status."],"exampleFix":"// before\nawait usePluginStore.getState().login('douyin')\n\n// after\nconst { status } = usePluginStore.getState()\nif (status !== Status.READY) {\n  await waitForPluginReady()\n}\nawait usePluginStore.getState().login('douyin')","handlingStrategy":"validation","validationCode":"const { status } = usePluginStore.getState()\nif (status !== Status.READY) {\n  await waitForPluginReady(timeoutMs) // subscribe to status changes\n}\nawait login(platform)","typeGuard":"function canLogin(status: Status): boolean {\n  return status !== Status.NOT_INSTALLED && status === Status.READY\n}","tryCatchPattern":"try {\n  await login(platform)\n}\ncatch (e) {\n  if (e.message === ERROR_MESSAGES.PLUGIN_NOT_READY) {\n    showAuthorizePermissionsDialog()\n    return\n  }\n  throw e\n}","preventionTips":["Await status READY via a store subscription before invoking login","Surface the extension's permission grant UI when status is stuck non-ready","Debounce login clicks during the startup handshake window","Handle extension updates that require re-authorization with a clear prompt"],"tags":["browser-extension","plugin","permissions","state-guard"],"backgroundTag":"plugin-not-ready","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}