{"record":{"id":"7262a2de997e33ba","repo":"Tencent/WeKnora","slug":"metaso-response-exceeds-d-bytes","errorCode":null,"errorMessage":"Metaso response exceeds %d bytes","messagePattern":"Metaso response exceeds (.+?) bytes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/web_search/metaso.go","lineNumber":149,"sourceCode":"\t\t\t\tresult.PublishedAt = &publishedAt\n\t\t\t}\n\t\t}\n\t\tresults = append(results, result)\n\t\tif len(results) >= maxResults {\n\t\t\tbreak\n\t\t}\n\t}\n\tlogger.Infof(ctx, \"[WebSearch][Metaso] returned %d results\", len(results))\n\treturn results, nil\n}\n\nfunc readMetasoResponseBody(reader io.Reader) ([]byte, error) {\n\tbody, err := io.ReadAll(io.LimitReader(reader, maxMetasoResponseBytes+1))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read Metaso response: %w\", err)\n\t}\n\tif len(body) > maxMetasoResponseBytes {\n\t\treturn nil, fmt.Errorf(\"Metaso response exceeds %d bytes\", maxMetasoResponseBytes)\n\t}\n\treturn body, nil\n}\n\nfunc metasoHTTPError(statusCode int, body []byte) error {\n\tvar apiError struct {\n\t\tMessage string `json:\"message\"`\n\t\tError   string `json:\"error\"`\n\t}\n\tif json.Unmarshal(body, &apiError) == nil {\n\t\tdetail := strings.TrimSpace(apiError.Message)\n\t\tif detail == \"\" {\n\t\t\tdetail = strings.TrimSpace(apiError.Error)\n\t\t}\n\t\tif detail != \"\" {\n\t\t\treturn fmt.Errorf(\"Metaso API returned status %d: %s\", statusCode, detail)\n\t\t}\n\t}","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/web_search/metaso.go#L131-L167","documentation":"Returned by readMetasoResponseBody when the response body exceeds maxMetasoResponseBytes (detected by reading one byte past the cap). The payload is abnormally large — likely an error page or runaway result set — and is rejected instead of loading it into memory.","triggerScenarios":"Thrown at internal/infrastructure/web_search/metaso.go:149 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Reduce maxResults to shrink the expected payload","Investigate why Metaso returned an oversized body (log a truncated sample)","Raise the limit only if legitimate responses are being cut off"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}