linshenkx/prompt-optimizer · error · Error

Missing Prompt Garden base URL

Error message

Missing Prompt Garden base URL

What it means

Thrown by buildPromptGardenSuggestionsUrl when no Prompt Garden base URL can be resolved. The function normalizes options.gardenBaseUrl and requires a non-empty result, because the suggestions endpoint URL cannot be constructed without it. It is called by the url helper used by fetchPromptGardenSuggestions.

Source

Thrown at packages/ui/src/utils/prompt-garden-suggestions.ts:122

      ? (source as PromptGardenSuggestionSource)
      : null,
  }
}

const buildFallbackBrowseUrl = (gardenBaseUrl: string, mode: string): string => {
  const url = new URL(`${gardenBaseUrl}/prompts`)
  if (mode) {
    url.searchParams.set('mode', mode)
  }
  return url.toString()
}

export const buildPromptGardenSuggestionsUrl = (
  options: FetchPromptGardenSuggestionsOptions,
): string => {
  const gardenBaseUrl = normalizeBaseUrl(options.gardenBaseUrl)
  if (!gardenBaseUrl) {
    throw new Error('Missing Prompt Garden base URL')
  }

  const url = new URL(`${gardenBaseUrl}/api/public/prompts/suggestions`)
  url.searchParams.set('mode', options.mode)
  url.searchParams.set('limit', String(options.limit ?? DEFAULT_LIMIT))
  url.searchParams.set('strategy', options.strategy ?? 'mixed')

  const exclude = Array.from(new Set((options.exclude ?? []).map((item) => item.trim()).filter(Boolean)))
  if (exclude.length > 0) {
    url.searchParams.set('exclude', exclude.join(','))
  }

  const locale = normalizeString(options.locale)
  if (locale) {
    url.searchParams.set('locale', locale)
  }

  return url.toString()

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Pass a valid gardenBaseUrl in the options object
  2. Set the Prompt Garden base URL environment variable for your environment
  3. Ensure config is loaded before calling fetchPromptGardenSuggestions; guard the call behind a config check
  4. Verify the URL survives normalizeBaseUrl (scheme present, not whitespace-only)

Example fix

// before
const suggestions = await fetchPromptGardenSuggestions({ mode: 'recent' })
// after
const gardenBaseUrl = import.meta.env.VITE_PROMPT_GARDEN_BASE_URL
if (!gardenBaseUrl) throw new Error('Prompt Garden not configured')
const suggestions = await fetchPromptGardenSuggestions({ mode: 'recent', gardenBaseUrl })
Defensive patterns

Strategy: validation

Validate before calling

const gardenBaseUrl = import.meta.env.VITE_PROMPT_GARDEN_BASE_URL
if (!gardenBaseUrl || !gardenBaseUrl.trim()) {
  // skip feature or show config UI instead of calling
}

Type guard

const hasGardenBaseUrl = (
  options: FetchPromptGardenSuggestionsOptions,
): boolean => Boolean(normalizeBaseUrl(options.gardenBaseUrl))

Try / catch

try {
  const url = buildPromptGardenSuggestionsUrl(options)
} catch (error) {
  if ((error as Error).message === 'Missing Prompt Garden base URL') {
    // degrade gracefully: hide suggestions feature
  }
}

Prevention

When it happens

Trigger: Calling fetchPromptGardenSuggestions or buildPromptGardenSuggestionsUrl without gardenBaseUrl; passing an empty string, whitespace, or a value that normalizeBaseUrl reduces to empty (e.g. malformed URL).

Common situations: Missing environment variable (e.g. VITE_PROMPT_GARDEN_BASE_URL) in the deployment config; dev environment where the garden service URL was never wired up; passing undefined options because the config object was not loaded yet.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


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