vxcontrol/pentagi · error · FatalError
failed to build request: %v
Error message
failed to build request: %v
What it means
Fatal error from the Firecrawl searcher's Handle (backend/pkg/tools/searchers/firecrawl.go) when http.NewRequest fails while building the POST search request. Practically only occurs with an invalid configured FIRCRAWL server URL. Retry will not help until configuration is fixed.
Source
Thrown at backend/pkg/tools/searchers/firecrawl.go:158
// sources is intentionally omitted: /v2/search defaults to ["web"], which is
// all this tool consumes, and it avoids the string-vs-object shape ambiguity
// that field carries across the API/SDK layers.
reqPayload := firecrawlRequest{
Query: query,
Limit: maxResults,
ScrapeOptions: &firecrawlScrapeOptions{
Formats: []string{"markdown"},
OnlyMainContent: true,
},
}
reqBody, err := json.Marshal(reqPayload)
if err != nil {
return "", Fatal(fmt.Errorf("failed to marshal request body: %v", err))
}
req, err := http.NewRequest(http.MethodPost, f.searchURL(), bytes.NewBuffer(reqBody))
if err != nil {
return "", Fatal(fmt.Errorf("failed to build request: %v", err))
}
req = req.WithContext(ctx)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+f.apiKey())
resp, err := client.Do(req)
if err != nil {
return "", Retryable(fmt.Errorf("failed to do request: %v", err), 0)
}
defer resp.Body.Close()
return f.parseHTTPResponse(ctx, query, resp)
}
func (f *firecrawl) parseHTTPResponse(ctx context.Context, query string, resp *http.Response) (string, error) {
switch resp.StatusCode {
case http.StatusOK:View on GitHub (pinned to ea665308ba)
Solutions
- Print/log f.searchURL() and fix the configured base URL (must include scheme).
- Validate the URL with url.Parse in a quick test before deployment.
- Set the Firecrawl server URL to a canonical https:// value in env/settings.
- Ensure no control characters or raw spaces are interpolated into the URL.
Example fix
// before FIRECRAWL_SERVER_URL=firecrawl.dev/v2 # missing scheme // after FIRECRAWL_SERVER_URL=https://api.firecrawl.dev/v2
Defensive patterns
Strategy: validation
Validate before calling
u, err := url.Parse(cfg.ServerURL)
if err != nil || u.Scheme == "" || u.Host == "" {
return fmt.Errorf("invalid firecrawl server url: %q", cfg.ServerURL)
} Prevention
- Always include the https:// scheme in server URL config.
- Validate URL config at startup, not at request time.
- Avoid string concatenation into URLs; use url.Values/path joins.
When it happens
Trigger: searchURL() produces a malformed URL (e.g. empty or invalid SERVER_URL / base path with control characters or bad percent-encoding).
Common situations: Misconfigured Firecrawl server URL env var (spaces, missing scheme, typo like 'htp://'), empty config making the URL invalid.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
- failed to create search request: %w
- failed to create http client: %w
- unexpected status code: %d
- failed to create request: %w
- invalid searxng base URL: %w
AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01).
Data as JSON: /api/errors/c63a0e5a45482cfd.
Report an issue: GitHub.