bytebase/bytebase · error
failed to construct webhook POST request to %s
Error message
failed to construct webhook POST request to %s
What it means
After marshaling, postMessage builds the POST with http.NewRequest against context.URL; this error wraps any http.NewRequest failure with the target URL. NewRequest fails mainly on an unparseable URL (missing/invalid scheme) or an invalid HTTP method.
Source
Thrown at backend/plugin/webhook/slack/slack.go:224
if context.DirectMessage && len(context.MentionEndUsers) > 0 {
if postDirectMessage(context) {
return nil
}
slog.Warn("failed to send direct messages for slack users, fallback to normal webhook", slog.String("event", context.EventType))
}
return postMessage(context)
}
func postMessage(context webhook.Context) error {
post := BuildMessage(context)
body, err := json.Marshal(post)
if err != nil {
return errors.Wrapf(err, "failed to marshal webhook POST request to %s", context.URL)
}
req, err := http.NewRequest("POST",
context.URL, bytes.NewBuffer(body))
if err != nil {
return errors.Wrapf(err, "failed to construct webhook POST request to %s", context.URL)
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{
Timeout: webhook.Timeout,
}
resp, err := client.Do(req)
if err != nil {
return errors.Wrapf(err, "failed to POST webhook to %s", context.URL)
}
b, err := io.ReadAll(resp.Body)
if err != nil {
return errors.Wrapf(err, "failed to read POST webhook response from %s", context.URL)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {View on GitHub (pinned to 1870550677)
Solutions
- Validate the Slack webhook URL is a well-formed https URL before calling Post (url.ParseRequestURI and check scheme)
- Fix the workspace webhook configuration so context.URL is a complete https://hooks.slack.com/... address
- Trim whitespace and ensure no unresolved template placeholders remain in the configured URL
Example fix
// before
u := settings.SlackWebhookURL // possibly empty
// after
u := strings.TrimSpace(settings.SlackWebhookURL)
if _, err := url.ParseRequestURI(u); err != nil || !strings.HasPrefix(u, "https://") { return errors.New("invalid slack webhook url") } Defensive patterns
Strategy: validation
Validate before calling
u, err := url.ParseRequestURI(strings.TrimSpace(webhookURL)); if err != nil || u.Scheme != "https" { return errors.New("invalid slack webhook url") } Try / catch
if err := webhook.Post(ctx); err != nil { if strings.Contains(err.Error(), "failed to construct webhook POST request") { /* reconfigure URL */ } } Prevention
- Validate the webhook URL at workspace-settings save time, not only at send time
- Reject empty or non-https URLs in configuration UI
When it happens
Trigger: Calling Post with a webhook context whose URL is empty, lacks an http(s) scheme, or contains characters invalid in a URL.
Common situations: Slack webhook URL not configured or left empty in workspace settings; URL copied with whitespace or bad scheme (e.g. 'slack.com/hooks/...' without https://); configuration template not substituted so URL contains literal placeholders.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- failed to construct Google Chat webhook POST request
- failed to construct webhook POST request to %s
- failed to construct webhook POST request to %s
- failed to construct %s %s
- failed to construct webhook POST request to %s
AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06).
Data as JSON: /api/errors/760d6d2250dfcf7a.
Report an issue: GitHub.