vxcontrol/pentagi · error · Fatal
failed to build request: %v
Error message
failed to build request: %v
What it means
traversaal.search returns Fatal 'failed to build request: %v' when http.NewRequest(http.MethodPost, traversaalURL, ...) fails. NewRequest errors on an invalid method or an unparseable URL, so this means the traversaalURL constant/config is malformed — a deployment/build-time problem, not a runtime network issue.
Source
Thrown at backend/pkg/tools/searchers/traversaal.go:88
func (t *traversaal) search(ctx context.Context, query string) (string, error) {
client, err := system.GetHTTPClient(t.cfg)
if err != nil {
return "", Fatal(fmt.Errorf("failed to create http client: %w", err))
}
reqBody, err := json.Marshal(struct {
Query string `json:"query"`
}{
Query: query,
})
if err != nil {
return "", Fatal(fmt.Errorf("failed to marshal request body: %v", err))
}
req, err := http.NewRequest(http.MethodPost, traversaalURL, 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("x-api-key", t.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 t.parseHTTPResponse(resp)
}
func (t *traversaal) parseHTTPResponse(resp *http.Response) (string, error) {
if resp.StatusCode != http.StatusOK {
err := fmt.Errorf("unexpected status code: %d", resp.StatusCode)View on GitHub (pinned to ea665308ba)
Solutions
- Read the wrapped error; NewRequest reports url.Parse failures precisely.
- Verify the Traversaal base URL env var is a valid absolute https:// URL.
- Validate the URL at startup (url.Parse) so bad config fails fast.
- If traversaalURL is hardcoded, check the constant wasn't corrupted by edits.
Example fix
// before: placeholder left in env TRAVERSAAL_SERVER_URL=your-api-key-here // after: valid endpoint TRAVERSAAL_SERVER_URL=https://api.traversaal.ai/hybrid/live
Defensive patterns
Strategy: validation
Validate before calling
if u, err := url.Parse(traversaalURL); err != nil || u.Scheme == "" || u.Host == "" {
return fmt.Errorf("invalid traversaal URL: %q", traversaalURL)
} Try / catch
result, err := traversaalSearcher.Handle(ctx, req)
var f *searchers.FatalError
if errors.As(err, &f) && strings.Contains(f.Error(), "failed to build request") {
return "", fmt.Errorf("check TRAVERSAAL server URL config: %w", err)
} Prevention
- Validate the endpoint URL with url.Parse at searcher construction
- Require absolute https:// URLs in configuration; reject placeholders
- Fail fast at boot if the configured URL is empty or malformed
When it happens
Trigger: http.NewRequest returns err because traversaalURL (or its configured override) is not a valid absolute URL (e.g. missing scheme, control characters, bad host).
Common situations: Misconfigured TRAVERSAAL server URL env var with spaces or missing https://; a fork pointing traversaalURL at an empty or placeholder value; config substitution injecting invalid characters.
Related errors
- failed to create http client: %w
- failed to create search request: %w
- failed to build request: %v
- failed to create request: %w
- failed to create request: %w
AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01).
Data as JSON: /api/errors/2cb986c8492c984c.
Report an issue: GitHub.