Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Ren0503
Copy link
Contributor

@Ren0503 Ren0503 commented Sep 16, 2025

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 16, 2025

Summary by CodeRabbit

  • Bug Fix
    • Sub-modules now inherit the parent interceptor by default when none is provided, ensuring consistent interception behavior across nested modules. This reduces manual configuration and prevents unexpected gaps in logging, monitoring, or policy enforcement. Existing setups that explicitly define an interceptor remain unchanged, while modules without one benefit from predictable, uniform behavior without additional configuration.

Walkthrough

A nil-check was added in DynamicModule.New to default a sub-module’s interceptor to its parent’s interceptor when the new module’s interceptor is unset. No other logic or public signatures changed.

Changes

Cohort / File(s) Summary of Changes
Interceptor inheritance in module creation
core/module.go
In DynamicModule.New, if newMod.interceptor is nil, assign m.interceptor so sub-modules inherit the parent's interceptor when unspecified. No other functional edits.

Sequence Diagram(s)

sequenceDiagram
  actor Caller
  participant Parent as Parent Module
  participant Factory as DynamicModule.New
  participant Child as New Sub-Module

  Caller->>Parent: Create sub-module
  Parent->>Factory: New()
  Note over Factory: Assemble DataProviders & Middlewares
  alt Interceptor not provided
    Factory->>Factory: if newMod.interceptor == nil
    Factory->>Child: set interceptor = Parent.interceptor
    Note right of Child: Inherits parent's interceptor (changed behavior)
  else Interceptor provided
    Factory->>Child: keep provided interceptor
  end
  Factory-->>Caller: return Child
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

A hop and a bop through code I steer,
If nil, I borrow what parent holds dear.
Interceptors inherit—no fuss, no fear,
Sub-mods align, the path is clear.
Thump-thump! says the rabbit engineer. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description Check ❓ Inconclusive No author-provided PR description is present, so there is no explicit description to evaluate; under the guidelines a missing or empty description is inconclusive because it does not provide reviewer-facing context even though file-level summaries show the interceptor propagation change. Please add a short description summarizing what changed, the motivation, any behavioral impact or tests, and links to related issues or design notes so reviewers have sufficient context.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title accurately summarizes the primary change: the diff makes a child module inherit the parent's interceptor (DynamicModule.New now propagates m.interceptor to newMod when nil), so it directly reflects the main change in the changeset; the wording is slightly ungrammatical but still clear.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/ren/328-fix-pass-interceptor-to-child

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

@Ren0503 Ren0503 added this to the TinhTinh Release v2.3.4 milestone Sep 16, 2025
@codecov
Copy link

codecov bot commented Sep 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Ren0503 Ren0503 linked an issue Sep 16, 2025 that may be closed by this pull request
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2c4d452 and 1b45ee9.

📒 Files selected for processing (1)
  • core/module.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)

Comment on lines +104 to +106
if newMod.interceptor == nil {
newMod.interceptor = m.interceptor
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

🧩 Analysis chain

Interceptor inheritance is applied too early and gets overwritten by initModule.

initModule unconditionally assigns module.interceptor = opt.Interceptor (Line 137). Your pre-init nil-check sets newMod.interceptor, but it’s then clobbered when opt.Interceptor is nil. Do the fallback on opt before calling initModule, or guard the assignment inside initModule.

Apply this diff in New():

   newMod := &DynamicModule{isRoot: false}
   newMod.DataProviders = append(newMod.DataProviders, m.GetExports()...)
   newMod.Middlewares = append(newMod.Middlewares, m.Middlewares...)
-  if newMod.interceptor == nil {
-    newMod.interceptor = m.interceptor
-  }
+  // Inherit parent interceptor only when none provided
+  if opt.Interceptor == nil {
+    opt.Interceptor = m.interceptor
+  }

   initModule(newMod, opt)
   return newMod

Alternatively (if you prefer keeping the current call site unchanged), guard the interceptor set in initModule:

-  module.interceptor = opt.Interceptor
+  if opt.Interceptor != nil {
+    module.interceptor = opt.Interceptor
+  }

Run to confirm no other writes override the interceptor unexpectedly:


🏁 Script executed:

#!/bin/bash
# List all assignments to .interceptor to ensure no later overwrite
rg -n --type=go -C2 '\.interceptor\s*='

Length of output: 1298


Fix interceptor inheritance being clobbered by initModule

initModule unconditionally sets module.interceptor = opt.Interceptor (core/module.go:137), which overwrites the fallback done earlier in New() (core/module.go:104–106). Either apply the fallback to opt before calling initModule or guard the assignment in initModule.

Apply this diff in New():

   newMod := &DynamicModule{isRoot: false}
   newMod.DataProviders = append(newMod.DataProviders, m.GetExports()...)
   newMod.Middlewares = append(newMod.Middlewares, m.Middlewares...)
-  if newMod.interceptor == nil {
-    newMod.interceptor = m.interceptor
-  }
+  // Inherit parent interceptor only when none provided
+  if opt.Interceptor == nil {
+    opt.Interceptor = m.interceptor
+  }

   initModule(newMod, opt)
   return newMod

Or guard inside initModule:

-  module.interceptor = opt.Interceptor
+  if opt.Interceptor != nil {
+    module.interceptor = opt.Interceptor
+  }

core/module.go:104–106,137.

🤖 Prompt for AI Agents
core/module.go lines 104-106 and 137: New() sets a fallback interceptor on
newMod (lines 104–106) but initModule unconditionally assigns module.interceptor
= opt.Interceptor at line 137, clobbering the fallback; either copy the fallback
into opt.Interceptor before calling initModule so initModule uses the
already-resolved interceptor, or change initModule to only assign
module.interceptor = opt.Interceptor if opt.Interceptor != nil (i.e., guard the
assignment) so the fallback set in New() isn't overwritten.

@Ren0503 Ren0503 merged commit d773ccc into master Sep 16, 2025
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.

Global Interceptor Not Pass From Parent Module to Child Module

2 participants