amir20/dozzle · error

failed to create request

Error message

failed to create request

What it means

cloudCallback builds a POST to `{DOLIGENCE_URL}/api/exchange-token` using http.NewRequestWithContext. If request construction fails (essentially only on an unparsable URL), it logs and returns 500 with this message. The cloud URL comes from the DOLIGENCE_URL env var or the hardcoded default.

Solutions

  1. Print/inspect the DOLIGENCE_URL value and remove stray whitespace or control characters.
  2. Set DOLIGENCE_URL to a valid absolute URL such as https://doligence.dozzle.dev.
  3. Unset DOLIGENCE_URL to fall back to the built-in default cloud endpoint.

Example fix

// before
DOLIGENCE_URL=https://doligence.dozzle.dev /api
// after
DOLIGENCE_URL=https://doligence.dozzle.dev
Defensive patterns

Strategy: validation

Validate before calling

const raw = process.env.DOLIGENCE_URL;
if (raw && !/^https?:\/\/[^\s]+$/.test(raw.trim())) {
    throw new Error(`DOLIGENCE_URL is not a valid URL: ${JSON.stringify(raw)}`);
}

Prevention

When it happens

Trigger: DOLIGENCE_URL env var set to a value that cannot be parsed as a URL (e.g. contains spaces, invalid characters, or control characters), producing a url.Parse error inside http.NewRequestWithContext.

Common situations: Operator sets DOLIGENCE_URL with a trailing space or newline in a compose file; quoting mistakes inject invalid characters; missing scheme plus malformed host producing an unparseable URL.

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


AI-assisted analysis of amir20/dozzle@d9463cbe21 (2026-09-07). Data as JSON: /api/errors/af02b43c4f903d6c. Report an issue: GitHub.

Appendix: source

Thrown at internal/web/cloud.go:63

	token := r.URL.Query().Get("token")
	from := r.URL.Query().Get("from")
	if token == "" {
		http.Error(w, "missing token parameter", http.StatusBadRequest)
		return
	}

	cloudURL := os.Getenv("DOLIGENCE_URL")
	if cloudURL == "" {
		cloudURL = "https://doligence.dozzle.dev"
	}

	exchangeURL := fmt.Sprintf("%s/api/exchange-token", cloudURL)

	client := cloudHTTPClient
	req, err := http.NewRequestWithContext(r.Context(), http.MethodPost, exchangeURL, nil)
	if err != nil {
		log.Error().Err(err).Msg("Failed to create request")
		http.Error(w, "failed to create request", http.StatusInternalServerError)
		return
	}
	req.Header.Set("User-Agent", dispatcher.UserAgent)
	q := req.URL.Query()
	q.Set("token", token)
	req.URL.RawQuery = q.Encode()

	resp, err := client.Do(req)
	if err != nil {
		log.Error().Err(err).Msg("Failed to exchange token")
		http.Error(w, "failed to exchange token", http.StatusInternalServerError)
		return
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		body, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))
		log.Error().Int("status", resp.StatusCode).Str("body", string(body)).Msg("Token exchange failed")

View on GitHub (pinned to d9463cbe21)