linshenkx/prompt-optimizer · error · ImageError

CONFIG_NOT_FOUND

CONFIG_NOT_FOUND

Error message

CONFIG_NOT_FOUND

What it means

After base validation passes, validateText2ImageRequest looks up the model config by request.configId via imageModelManager.getConfig. A missing (deleted or never-created) config throws CONFIG_NOT_FOUND with the configId attached.

Source

Thrown at packages/core/src/services/image/service.ts:91

    await this.validateText2ImageRequest(text2image)
  }

  async validateText2ImageRequest(request: Text2ImageRequest): Promise<void> {
    // 显式文生图:不允许携带 inputImage(即使调用方用 any 绕过类型)
    const unsafeInputImage = (request as unknown as { inputImage?: unknown }).inputImage
    const unsafeInputImages = (request as unknown as { inputImages?: unknown }).inputImages
    if (unsafeInputImage !== undefined && unsafeInputImage !== null) {
      throw new ImageError(IMAGE_ERROR_CODES.TEXT2IMAGE_INPUT_IMAGE_NOT_ALLOWED)
    }
    if (Array.isArray(unsafeInputImages) && unsafeInputImages.length > 0) {
      throw new ImageError(IMAGE_ERROR_CODES.TEXT2IMAGE_INPUT_IMAGE_NOT_ALLOWED)
    }

    await this.validateBaseRequest(request)

    const config = await this.imageModelManager.getConfig(request.configId)
    if (!config) {
      throw new ImageError(IMAGE_ERROR_CODES.CONFIG_NOT_FOUND, undefined, { configId: request.configId })
    }

    // 能力校验:优先使用 config.model(动态/自定义模型),静态列表作为兜底
    const configModel = config.model
    const staticModels = this.registry.getStaticModels(config.providerId)
    const staticModel = staticModels.find(m => m.id === config.modelId)
    const capabilities = configModel?.capabilities ?? staticModel?.capabilities
    const modelName = configModel?.name ?? staticModel?.name ?? config.modelId

    if (capabilities && !capabilities.text2image) {
      // 对于仅支持图生图的模型,给出更明确指引
      if (capabilities.image2image) {
        throw new ImageError(IMAGE_ERROR_CODES.MODEL_ONLY_SUPPORTS_IMAGE2IMAGE_NEED_INPUT, undefined, { modelName })
      }
      throw new ImageError(IMAGE_ERROR_CODES.MODEL_NOT_SUPPORT_TEXT2IMAGE, undefined, { modelName })
    }
  }

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. List existing configs via imageModelManager and use a valid configId
  2. Refresh the config picker in the UI when a config-delete event fires
  3. Call ensureInitialized() on the manager before first generate
  4. If the stale id came from persisted state, clear it and prompt re-selection

Example fix

// before
await service.generateText2Image({ configId: savedConfigId, prompt })

// after
const config = await manager.getConfig(savedConfigId)
if (!config) throw new Error(`Config ${savedConfigId} no longer exists — re-select a model`)
await service.generateText2Image({ configId: config.id, prompt })
Defensive patterns

Strategy: validation

Validate before calling

const config = await imageModelManager.getConfig(request.configId)
if (!config) {
  throw new Error(`Model config ${request.configId} not found — re-select a model`)
}
await service.generateText2Image(request)

Try / catch

try {
  await service.generateText2Image(request)
} catch (e) {
  if (e instanceof ImageError && e.code === IMAGE_ERROR_CODES.CONFIG_NOT_FOUND) {
    await refreshConfigList(); promptReselect(); return
  }
  throw e
}

Prevention

When it happens

Trigger: Calling generateText2Image with a configId that does not exist in the manager: deleted config, typo/uuid mismatch, stale configId persisted in user state after a config was removed, or manager not yet initialized.

Common situations: User deleted the model config but the UI still holds the old selection; configId persisted in localStorage/DB from a previous install; race where generate is called before ensureInitialized completes; environment mismatch (configs stored per-profile).

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/5ba66d1c6110b2cf. Report an issue: GitHub.