Skip to content

🐛 Add missing Context() and SetContext() methods to Ctx interface#3626

Closed
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-3624
Closed

🐛 Add missing Context() and SetContext() methods to Ctx interface#3626
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-3624

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jul 27, 2025

The v3 documentation states that UserContext was renamed to Context() which should return a context.Context object, and SetUserContext was renamed to SetContext(). However, these methods were missing from the Ctx interface in v3.0.0-beta.5.

While DefaultCtx already implements context.Context directly (which is cleaner), users following the migration guide expect these methods to exist as documented.

Changes

Added Context() method:

  • Returns the DefaultCtx itself since it already implements context.Context
  • Allows users to call c.Context() as documented in the migration guide
  • Maintains compatibility with existing code that passes Ctx directly as context.Context

Added SetContext() method:

  • Equivalent to Locals() but matches the context API naming
  • Allows setting context values that can be retrieved via Value()

Example usage:

app.Get("/", func(c fiber.Ctx) error {
    // Set context values
    c.SetContext("user", "john")
    
    // Get the context
    ctx := c.Context()
    
    // Pass to functions expecting context.Context
    processRequest(ctx)
    
    return c.SendString("OK")
})

func processRequest(ctx context.Context) {
    user := ctx.Value("user") // "john"
    // ... use context
}

Testing

  • Added comprehensive tests for both methods
  • Verified all existing tests continue to pass (1713 tests)
  • Manual testing confirms Ctx can be passed as context.Context to other functions

Fixes #3624.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • exampleretry.com
    • Triggering command: /tmp/go-build2872156064/b273/client.test -test.paniconexit0 -test.v=test2json -test.timeout=10m0s -test.count=1 -test.shuffle=on (dns block)
    • Triggering command: /tmp/go-build160186565/b273/client.test -test.paniconexit0 -test.v=test2json -test.timeout=10m0s -test.count=1 -test.shuffle=on (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Add Context() method that returns the DefaultCtx itself since it implements context.Context
- Add SetContext() method for setting context values (equivalent to Locals)
- Regenerate interface using ifacemaker
- Add comprehensive tests for both methods
- Verify that Ctx can be passed as context.Context to other functions

Co-authored-by: ReneWerner87 <7063188+ReneWerner87@users.noreply.github.com>
Copilot AI changed the title [WIP] 🐛 [Bug]: Context() context.Context was removed from v3.0.0-beta.5 🐛 Add missing Context() and SetContext() methods to Ctx interface Jul 27, 2025
Copilot AI requested a review from ReneWerner87 July 27, 2025 19:45
@ReneWerner87
Copy link
Copy Markdown
Member

@copilot I think it was just important that the documentation be adapted
to the functions that exist or have been removed; we had already agreed on that beforehand.

Co-authored-by: ReneWerner87 <7063188+ReneWerner87@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jul 28, 2025

@copilot I think it was just important that the documentation be adapted
to the functions that exist or have been removed; we had already agreed on that beforehand.

You're absolutely right. I've fixed the documentation instead of adding the methods. The issue was contradictory documentation - it stated that UserContext was "renamed to Context()" and SetUserContext was "renamed to SetContext()" in one section, but correctly stated these methods were removed in another section.

Since DefaultCtx already implements context.Context directly, users can pass Ctx directly to functions expecting context.Context. The documentation now correctly reflects this: UserContext and SetUserContext were removed, and users should use Ctx directly or Locals() for storing values.

Fixed in commit 179c9e2.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • exampleretry.com
    • Triggering command: go run gotest.tools/gotestsum@latest -f testname -- ./... -race -count=1 -shuffle=on (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 1, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Join our Discord community for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ReneWerner87 ReneWerner87 added this to the v3 milestone Aug 1, 2025
@ReneWerner87
Copy link
Copy Markdown
Member

closed by #3650

@github-project-automation github-project-automation Bot moved this to Done in v3 Aug 1, 2025
@ReneWerner87 ReneWerner87 deleted the copilot/fix-3624 branch January 27, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

🐛 [Bug]: Context() context.Context was removed from v3.0.0-beta.5

2 participants