{"record":{"id":"ce9fd43dc294f5f1","repo":"chatboxai/chatbox","slug":"license-key-is-required-for-image-generation","errorCode":null,"errorMessage":"License key is required for image generation","messagePattern":"License key is required for image generation","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/renderer/stores/imageGenerationActions.ts","lineNumber":37,"sourceCode":"  addGeneratedImage,\n  createRecord,\n  IMAGE_GEN_LIST_QUERY_KEY,\n  IMAGE_GEN_QUERY_KEY,\n  imageGenerationStore,\n  updateRecord,\n} from './imageGenerationStore'\nimport { queryClient } from './queryClient'\nimport { settingsStore } from './settingsStore'\n\nconst log = getLogger('image-generation-actions')\n\n// AbortController for cancelling in-flight polling\nlet currentAbortController: AbortController | null = null\n\nfunction getLicenseKey(): string {\n  const licenseKey = settingsStore.getState().licenseKey\n  if (!licenseKey) {\n    throw new Error('License key is required for image generation')\n  }\n  return licenseKey\n}\n\nfunction shouldUseAsyncPath(provider: string): boolean {\n  return provider === ModelProviderEnum.ChatboxAI\n}\n\nfunction getErrorRecordUpdate(\n  error: unknown\n): Pick<ImageGeneration, 'status' | 'error' | 'errorCode' | 'errorItemUuid'> {\n  const normalizedError = error instanceof Error ? error : new Error(`${error}`)\n  return {\n    status: 'error',\n    error: normalizedError.message,\n    errorCode: error instanceof BaseError ? error.code : undefined,\n    errorItemUuid: undefined,\n  }","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/chatboxai/chatbox/blob/81571269addb6bafb589a920b2883f1e1e084fd1/src/renderer/stores/imageGenerationActions.ts#L19-L55","documentation":"Thrown by getLicenseKey(), the gatekeeper for every image-generation action. It reads settingsStore.getState().licenseKey and refuses to proceed when empty. Image generation is a Chatbox AI licensed feature, so a missing license key is a hard precondition — the call never reaches the network.","triggerScenarios":"Any startImageGeneration / resumeGeneration / retryGeneration path calls getLicenseKey() before building the request, and licenseKey in settingsStore is empty/undefined. This happens when the user selected Chatbox AI image generation but never entered a license key, or the key was cleared on logout/settings reset.","commonSituations":"Fresh install with no license entered, user logged out (license cleared), settings reset, or a flow that reaches image generation without the settings gate the UI normally enforces.","solutions":["Guard at the UI layer: disable the image-generation entry point until settingsStore.licenseKey is non-empty.","Show the license-entry/settings modal before calling startImageGeneration.","Ensure logout/settings-reset clears currentGeneratingId so no stale action runs without a key.","Return a typed error (BaseError with code) instead of a generic Error so the UI can route to license setup."],"exampleFix":"// before\nfunction getLicenseKey(): string {\n  const licenseKey = settingsStore.getState().licenseKey\n  if (!licenseKey) throw new Error('License key is required for image generation')\n  return licenseKey\n}\n// after\nfunction getLicenseKey(): string {\n  const licenseKey = settingsStore.getState().licenseKey\n  if (!licenseKey) throw new LicenseRequiredError('image-generation')\n  return licenseKey\n}","handlingStrategy":"validation","validationCode":"const hasLicense = Boolean(settingsStore.getState().licenseKey)\nif (!hasLicense) {\n  openLicenseSettings()\n  return\n}","typeGuard":"function hasLicenseKey(s: { licenseKey?: string | null }): s is { licenseKey: string } {\n  return typeof s.licenseKey === 'string' && s.licenseKey.trim().length > 0\n}","tryCatchPattern":null,"preventionTips":["Disable image-generation entry points in the UI until a license key is present.","Clear currentGeneratingId on logout so no stale action runs without a key.","Use a typed LicenseRequiredError so the UI can route to license setup."],"tags":["image-generation","license","validation","chatbox-ai"],"backgroundTag":null,"analyzedSha":"81571269addb6bafb589a920b2883f1e1e084fd1","analyzedAt":"2026-08-12T21:51:44.981Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}