{"record":{"id":"322adb6bc4ac2de6","repo":"Tencent/WeKnora","slug":"create-request-w-322adb","errorCode":null,"errorMessage":"create request: %w","messagePattern":"create request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/docparser/mineru_converter.go","lineNumber":238,"sourceCode":"\tfor k, v := range fields {\n\t\t_ = writer.WriteField(k, v)\n\t}\n\n\tuploadFileName := minerUUploadFileName(fileName, fileType)\n\n\t// File part\n\tpart, err := writer.CreateFormFile(\"files\", uploadFileName)\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"create form file: %w\", err)\n\t}\n\tif _, err := part.Write(content); err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"write file content: %w\", err)\n\t}\n\twriter.Close()\n\n\thttpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, c.endpoint+\"/file_parse\", &body)\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"create request: %w\", err)\n\t}\n\thttpReq.Header.Set(\"Content-Type\", writer.FormDataContentType())\n\n\tclient := utils.NewSSRFSafeHTTPClient(utils.SSRFSafeHTTPClientConfig{\n\t\tTimeout:      mineruTimeout,\n\t\tMaxRedirects: 5,\n\t})\n\tresp, err := client.Do(httpReq)\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"HTTP request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\trespBody, _ := io.ReadAll(resp.Body)\n\t\treturn \"\", nil, fmt.Errorf(\"MinerU API status %d: %s\", resp.StatusCode, string(respBody))\n\t}\n","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/docparser/mineru_converter.go#L220-L256","documentation":"http.NewRequestWithContext failed while building the POST to endpoint + \"/file_parse\". This error means the request could not be constructed — almost always an invalid URL (unparseable/empty endpoint, bad characters, unsupported scheme) rather than a network problem.","triggerScenarios":"c.endpoint is empty, malformed (missing scheme, spaces, control chars), or c.endpoint + \"/file_parse\" doesn't parse as a valid URL.","commonSituations":"Misconfigured MinerU endpoint in config/env (e.g. missing http://, trailing newline or whitespace from an env var, wrong port); endpoint set to a unix-socket or relative path string.","solutions":["Log/inspect c.endpoint and validate it with url.Parse before constructing requests.","Fix the configured base URL: it must be an absolute http(s) URL, e.g. http://mineru:8000 (no trailing whitespace/newline).","Add a startup config check that fails fast if the endpoint doesn't parse.","Trim whitespace when loading the endpoint from env/config files."],"exampleFix":"// before\nhttpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, c.endpoint+\"/file_parse\", &body)\nif err != nil {\n    return \"\", nil, fmt.Errorf(\"create request: %w\", err)\n}\n// after\nbaseURL := strings.TrimSpace(c.endpoint)\nif u, perr := url.Parse(baseURL + \"/file_parse\"); perr != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return \"\", nil, fmt.Errorf(\"invalid mineru endpoint %q: %w\", baseURL, perr)\n}\nhttpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, baseURL+\"/file_parse\", &body)","handlingStrategy":"validation","validationCode":"u, err := url.Parse(strings.TrimSpace(endpoint) + \"/file_parse\")\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"invalid mineru endpoint %q\", endpoint)\n}","typeGuard":"func validEndpoint(endpoint string) bool {\n    u, err := url.Parse(strings.TrimSpace(endpoint))\n    return err == nil && (u.Scheme == \"http\" || u.Scheme == \"https\") && u.Host != \"\"\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"create request\") {\n    // configuration bug, not transient — fail fast, surface config error\n    return fmt.Errorf(\"misconfigured mineru endpoint: %w\", err)\n}","preventionTips":["Validate endpoint config at startup with url.Parse and fail fast","Trim whitespace/newlines when loading config from env or files","Require absolute http(s) URLs in configuration schemas","Add a smoke test that builds a request from the production config"],"tags":["http","url","configuration","mineru"],"backgroundTag":"invalid-url","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}