wtfutil/wtf · warning
panic(err)
Error message
panic(err)
What it means
NewWithHTTPClient parses the hardcoded defaultAPIURL constant and panics if url.Parse fails. Since the URL is a compile-time constant that is known-valid, this panic is effectively unreachable defensive code — it can only fire if the package constant is modified to an invalid URL (e.g. a fork or patched build).
Source
Thrown at modules/newrelic/client/main.go:36
// defaultAPIURL is the default base URL for New Relic's latest API.
defaultAPIURL = "https://api.newrelic.com/v2/"
// defaultTimeout is the default timeout for the http.Client used.
defaultTimeout = 5 * time.Second
)
// Client provides a set of methods to interact with the New Relic API.
type Client struct {
apiKey string
httpClient *http.Client
url *url.URL
}
// NewWithHTTPClient returns a new Client object for interfacing with the New
// Relic API, allowing for override of the http.Client object.
func NewWithHTTPClient(apiKey string, client *http.Client) *Client {
u, err := url.Parse(defaultAPIURL)
if err != nil {
panic(err)
}
return &Client{
apiKey: apiKey,
httpClient: client,
url: u,
}
}
// NewClient returns a new Client object for interfacing with the New Relic API.
func NewClient(apiKey string) *Client {
return NewWithHTTPClient(apiKey, &http.Client{Timeout: defaultTimeout})
}
View on GitHub (pinned to bb838c1ccb)
Solutions
- Check whether defaultAPIURL in modules/newrelic/client/main.go was modified and restore/fix the URL value
- If you intentionally changed it, make the value a syntactically valid absolute URL (scheme + host)
- Report/verify against upstream if using a fork
Example fix
// before const defaultAPIURL = "api.newrelic.com" // missing scheme, edited constant // after const defaultAPIURL = "https://api.newrelic.com/v2"
Defensive patterns
Strategy: validation
Validate before calling
// only relevant for forks editing defaultAPIURL
if _, err := url.Parse(defaultAPIURL); err != nil {
panic(fmt.Sprintf("defaultAPIURL is not a valid URL: %v", err))
} Try / catch
defer func() {
if r := recover(); r != nil {
log.Printf("newrelic client construction panicked: %v", r)
}
}()
c := newrelic.NewClient(apiKey) Prevention
- Never modify defaultAPIURL without validating it with url.Parse
- Keep the client package unmodified and configure endpoints through supported options
- Add a unit test asserting defaultAPIURL parses
When it happens
Trigger: NewClient → NewWithHTTPClient is called; url.Parse(defaultAPIURL) fails, which for the shipped constant should never happen — realistic only in forks/builds where defaultAPIURL was edited to a malformed string, or in exotic environments where the package was tampered with.
Common situations: Self-patched builds pointing defaultAPIURL at a private New Relic endpoint with a malformed URL value; misapplied patches; vendor-directory edits.
Related errors
AI-assisted analysis of wtfutil/wtf@bb838c1ccb (2026-09-03).
Data as JSON: /api/errors/893d998c4f413373.
Report an issue: GitHub.