{"record":{"id":"8c229c9d3a957288","repo":"Tencent/WeKnora","slug":"rate-limiter-w","errorCode":null,"errorMessage":"rate limiter: %w","messagePattern":"rate limiter: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/datasource/connector/notion/client.go","lineNumber":62,"sourceCode":"\nconst maxRetries = 3\n\n// sleepWithContext pauses for the given duration, returning early if ctx is cancelled.\nfunc sleepWithContext(ctx context.Context, d time.Duration) error {\n\tt := time.NewTimer(d)\n\tdefer t.Stop()\n\tselect {\n\tcase <-t.C:\n\t\treturn nil\n\tcase <-ctx.Done():\n\t\treturn ctx.Err()\n\t}\n}\n\n// doRequest performs an authenticated, rate-limited HTTP request to the Notion API.\nfunc (c *notionClient) doRequest(ctx context.Context, method, path string, body interface{}) ([]byte, error) {\n\tif err := c.limiter.Wait(ctx); err != nil {\n\t\treturn nil, fmt.Errorf(\"rate limiter: %w\", err)\n\t}\n\n\tvar bodyReader io.Reader\n\tif body != nil {\n\t\tbodyBytes, err := json.Marshal(body)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"marshal request body: %w\", err)\n\t\t}\n\t\tbodyReader = bytes.NewReader(bodyBytes)\n\t}\n\n\treq, err := http.NewRequestWithContext(ctx, method, c.baseURL+path, bodyReader)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"create request: %w\", err)\n\t}\n\treq.Header.Set(\"Authorization\", \"Bearer \"+c.token)\n\treq.Header.Set(\"Notion-Version\", NotionAPIVersion)\n\treq.Header.Set(\"Content-Type\", \"application/json\")","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/datasource/connector/notion/client.go#L44-L80","documentation":"In notionClient.doRequest, c.limiter.Wait(ctx) returns the context error (usually context.Canceled) when the caller cancels or the deadline expires while waiting for a rate-limiter slot. The request was never sent; the error is the cancellation reason.","triggerScenarios":"Thrown at internal/datasource/connector/notion/client.go:62 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped context error (DeadlineExceeded vs Canceled)","Increase or remove caller deadlines if waits are legitimately long","Check the limiter's rate budget if waits consistently time out"],"exampleFix":null,"handlingStrategy":"try-catch","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-08T10:18:20.063Z"}