{"record":{"id":"52c804babd86e1f0","repo":"Tencent/WeKnora","slug":"create-request-w-52c804","errorCode":null,"errorMessage":"create request: %w","messagePattern":"create request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/docparser/mineru_cloud_converter.go","lineNumber":134,"sourceCode":"\t}\n\n\tpayload := map[string]interface{}{\n\t\t\"files\":          []map[string]string{{\"name\": fileName, \"data_id\": uuid.New().String()}},\n\t\t\"model_version\":  modelVersion,\n\t\t\"is_ocr\":         c.ocrEnable,\n\t\t\"enable_formula\": c.formulaEnable,\n\t\t\"enable_table\":   c.tableEnable,\n\t\t\"language\":       c.language,\n\t}\n\n\tbody, err := json.Marshal(payload)\n\tif err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"marshal payload: %w\", err)\n\t}\n\n\thttpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+\"/file-urls/batch\", bytes.NewReader(body))\n\tif err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"create request: %w\", err)\n\t}\n\thttpReq.Header.Set(\"Authorization\", \"Bearer \"+c.apiKey)\n\thttpReq.Header.Set(\"Content-Type\", \"application/json\")\n\n\tclient := utils.NewSSRFSafeHTTPClient(utils.SSRFSafeHTTPClientConfig{Timeout: 30 * time.Second, MaxRedirects: 5})\n\tresp, err := client.Do(httpReq)\n\tif err != nil {\n\t\treturn \"\", \"\", 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 \"\", \"\", fmt.Errorf(\"API status %d: %s\", resp.StatusCode, string(respBody))\n\t}\n\n\tvar result batchApplyResponse\n\tif err := json.NewDecoder(resp.Body).Decode(&result); err != nil {","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/docparser/mineru_cloud_converter.go#L116-L152","documentation":"applyUploadURLs builds the POST to baseURL/file-urls/batch with http.NewRequestWithContext; if request construction fails (invalid method/URL), it returns \"create request: %w\". Since the method is a constant POST, this almost always means the configured baseURL is not a valid URL.","triggerScenarios":"Read -> applyUploadURLs where http.NewRequestWithContext fails because c.baseURL + \"/file-urls/batch\" does not parse as a valid URL (e.g. missing scheme, control characters, spaces).","commonSituations":"baseURL env var set without scheme (\"mineru.net\" instead of \"https://mineru.net\"); trailing spaces/newline in config; misparsed YAML/env config injecting quotes or whitespace into the URL.","solutions":["Check the wrapped cause and print/inspect the configured baseURL — it must be a full absolute URL including scheme.","Fix the env var/config to e.g. https://mineru.net/api/v4 (no spaces, no quotes, correct scheme).","Trim whitespace with strings.TrimSpace when loading the baseURL from environment/config.","Validate the URL with url.Parse at startup and fail fast if invalid."],"exampleFix":"// before\nbaseURL := os.Getenv(\"MINERU_BASE_URL\") // \"mineru.net/api/v4\" — no scheme\n// after\nbaseURL := strings.TrimSpace(os.Getenv(\"MINERU_BASE_URL\"))\nif u, err := url.Parse(baseURL); err != nil || u.Scheme == \"\" {\n    return nil, nil, fmt.Errorf(\"invalid mineru base url %q\", baseURL)\n}","handlingStrategy":"validation","validationCode":"u, err := url.Parse(strings.TrimSpace(baseURL))\nif err != nil || u.Scheme != \"https\" || u.Host == \"\" {\n    return fmt.Errorf(\"mineru baseURL must be an absolute https URL, got %q\", baseURL)\n}","typeGuard":"func isValidBaseURL(raw string) bool {\n    u, err := url.Parse(strings.TrimSpace(raw))\n    return err == nil && (u.Scheme == \"http\" || u.Scheme == \"https\") && u.Host != \"\"\n}","tryCatchPattern":"res, err := converter.Read(ctx, req)\nif err != nil {\n    if strings.Contains(err.Error(), \"create request\") {\n        return fmt.Errorf(\"mineru baseURL %q is not a valid URL; fix the endpoint config (include https://)\", baseURL)\n    }\n    return err\n}","preventionTips":["Always configure baseURL with an explicit https:// scheme.","Trim whitespace/newlines when loading the URL from env or YAML config.","Validate the URL with url.Parse at converter construction time, not at request time.","Keep the endpoint URL in a single config source to avoid divergent copies."],"tags":["http","configuration","url-validation"],"backgroundTag":"invalid-base-url","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}