Skip to content

docs: fix app.currentContext example (read the getter, don't assign to it)#1978

Merged
fengmk2 merged 1 commit into
koajs:masterfrom
DucMinhNe:docs/fix-currentcontext-example
Jun 9, 2026
Merged

docs: fix app.currentContext example (read the getter, don't assign to it)#1978
fengmk2 merged 1 commit into
koajs:masterfrom
DucMinhNe:docs/fix-currentcontext-example

Conversation

@DucMinhNe

@DucMinhNe DucMinhNe commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

The app.currentContext example assigns to the property:

function callSomeFunction () {
  app.currentContext = {} /* ctx of the middleware above */
}

But currentContext is a getter-only accessor (lib/application.js):

get currentContext () {
  if (this.ctxStorage) return this.ctxStorage.getStore()
}

There is no setter, so assigning to it throws TypeError: Cannot set property currentContext of #<Application> which has only a getter in strict mode (which is the default for ES modules / class bodies). The assignment is also backwards from what the surrounding text describes — "this will return the current context for the request" — so the example should read the property, which is exactly what the adjacent v3.1.0 example does via asyncLocalStorage.getStore().

This changes the example to read the getter:

function callSomeFunction () {
  const ctx = app.currentContext /* ctx of the middleware above */
}

Docs only.

Summary by Sourcery

Documentation:

  • Update the app.currentContext documentation example to read from the getter instead of assigning to it.

Summary by CodeRabbit

Release Notes

  • Documentation
    • Corrected example code in Koa v3 API documentation to properly demonstrate context retrieval.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 44903e88-051f-4424-abbf-2424f8147131

📥 Commits

Reviewing files that changed from the base of the PR and between 480a4f0 and a349e34.

📒 Files selected for processing (1)
  • docs/api/index.md

📝 Walkthrough

Walkthrough

This pull request corrects a code example in the Koa API documentation. The example for app.currentContext in the Koa v3 section was updated to properly demonstrate reading the current request context from app.currentContext into a local variable, rather than the prior incorrect example that showed assigning an empty object to app.currentContext.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: fixing a documentation example for app.currentContext to read the getter instead of assigning to it.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai

sourcery-ai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the documentation example for app.currentContext to correctly demonstrate reading from the getter-only property instead of assigning to it, aligning the sample with the actual API behavior and surrounding explanation.

Sequence diagram for using app.currentContext getter in docs example

sequenceDiagram
  participant Request
  participant Middleware as app_middleware
  participant Application as app
  participant Function as callSomeFunction

  Request->>app_middleware: handle request
  app_middleware->>app: set ctxStorage store
  Request-->>Function: later callSomeFunction()
  Function->>app: currentContext
  app-->>Function: ctx from ctxStorage.getStore()
Loading

File-Level Changes

Change Details Files
Correct the app.currentContext usage example to read from the getter-only property rather than assign to it.
  • Change the example function to declare a ctx constant sourced from app.currentContext.
  • Remove the incorrect assignment to app.currentContext that would throw in strict mode and contradicted the description of the API.
docs/api/index.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.90%. Comparing base (480a4f0) to head (a349e34).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1978   +/-   ##
=======================================
  Coverage   99.90%   99.90%           
=======================================
  Files           9        9           
  Lines        2109     2109           
=======================================
  Hits         2107     2107           
  Misses          2        2           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fengmk2 fengmk2 merged commit 78efdc8 into koajs:master Jun 9, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants