{"record":{"id":"893d998c4f413373","repo":"wtfutil/wtf","slug":"panic-err-893d99","errorCode":null,"errorMessage":"panic(err)","messagePattern":"panic\\(err\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"modules/newrelic/client/main.go","lineNumber":36,"sourceCode":"\t// defaultAPIURL is the default base URL for New Relic's latest API.\n\tdefaultAPIURL = \"https://api.newrelic.com/v2/\"\n\t// defaultTimeout is the default timeout for the http.Client used.\n\tdefaultTimeout = 5 * time.Second\n)\n\n// Client provides a set of methods to interact with the New Relic API.\ntype Client struct {\n\tapiKey     string\n\thttpClient *http.Client\n\turl        *url.URL\n}\n\n// NewWithHTTPClient returns a new Client object for interfacing with the New\n// Relic API, allowing for override of the http.Client object.\nfunc NewWithHTTPClient(apiKey string, client *http.Client) *Client {\n\tu, err := url.Parse(defaultAPIURL)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn &Client{\n\t\tapiKey:     apiKey,\n\t\thttpClient: client,\n\t\turl:        u,\n\t}\n}\n\n// NewClient returns a new Client object for interfacing with the New Relic API.\nfunc NewClient(apiKey string) *Client {\n\treturn NewWithHTTPClient(apiKey, &http.Client{Timeout: defaultTimeout})\n}\n","sourceCodeStart":18,"sourceCodeEnd":49,"githubUrl":"https://github.com/wtfutil/wtf/blob/bb838c1ccb0f0f3223690df44afdec663d622881/modules/newrelic/client/main.go#L18-L49","documentation":"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).","triggerScenarios":"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.","commonSituations":"Self-patched builds pointing defaultAPIURL at a private New Relic endpoint with a malformed URL value; misapplied patches; vendor-directory edits.","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"],"exampleFix":"// before\nconst defaultAPIURL = \"api.newrelic.com\" // missing scheme, edited constant\n// after\nconst defaultAPIURL = \"https://api.newrelic.com/v2\"","handlingStrategy":"validation","validationCode":"// only relevant for forks editing defaultAPIURL\nif _, err := url.Parse(defaultAPIURL); err != nil {\n    panic(fmt.Sprintf(\"defaultAPIURL is not a valid URL: %v\", err))\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        log.Printf(\"newrelic client construction panicked: %v\", r)\n    }\n}()\nc := newrelic.NewClient(apiKey)","preventionTips":["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"],"tags":["go","panic","newrelic","defensive-code"],"backgroundTag":"unreachable-defensive-panic","analyzedSha":"bb838c1ccb0f0f3223690df44afdec663d622881","analyzedAt":"2026-09-03T17:02:45.030Z","contentChangedAt":"2026-09-03T17:02:45.030Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}