Skip to content

fix: qualifier use over write #300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

akitaSummer
Copy link
Contributor

@akitaSummer akitaSummer commented Apr 2, 2025

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling in qualifier management by replacing disruptive error messages with non-intrusive warnings when duplicate implementations are detected, ensuring smoother operation without abrupt interruptions.

Copy link

coderabbitai bot commented Apr 2, 2025

Walkthrough

The changes update the error handling in two methods that manage qualifier implementations. In both methods, when a duplicate qualifier is detected, the code now logs a warning to the console instead of throwing an error. The behavior is altered in the addProtoQualifier method of the QualifierUtil class and in the addQualifierImpl method of the QualifierImplUtil class. No modifications were made to the exported or public entity signatures.

Changes

File(s) Change Summary
core/core-decorator/.../QualifierUtil.ts
core/dynamic-inject/.../QualifierImplUtil.ts
Replaced error throwing with console.warn(). Both methods now log warnings when a duplicate qualifier is detected, allowing execution to continue without interruption.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant QualifierUtil
    Caller ->> QualifierUtil: addProtoQualifier(clazz, attribute)
    activate QualifierUtil
    QualifierUtil ->> QualifierUtil: Check if qualifier is already implemented
    alt Qualifier exists
        QualifierUtil ->> Console: console.warn("Qualifier Warning: ...")
        Note right of QualifierUtil: Execution continues
    else Not implemented
        QualifierUtil ->> QualifierUtil: Add qualifier normally
    end
    deactivate QualifierUtil
Loading
sequenceDiagram
    participant Caller
    participant QualifierImplUtil
    Caller ->> QualifierImplUtil: addQualifierImpl(abstractClazz, qualifierValue, implClazz, isForceReplacement?)
    activate QualifierImplUtil
    QualifierImplUtil ->> QualifierImplUtil: Check if qualifier exists & isForceReplacement flag
    alt Duplicate qualifier without force replacement
        QualifierImplUtil ->> Console: console.warn("Qualifier Warning: ...")
        Note right of QualifierImplUtil: Execution continues
    else Normal situation
        QualifierImplUtil ->> QualifierImplUtil: Add qualifier implementation
    end
    deactivate QualifierImplUtil
Loading

Possibly related PRs

Suggested reviewers

  • killagu

Poem

I'm a bunny with a coding spree,
Hopping through functions so merrily.
No more errors to halt my race,
Warnings now keep up the pace.
Carrot hops and console grace! 🐇

Happy coding from a rabbit's space!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

core/core-decorator/src/util/QualifierUtil.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eggache".

(The package "eslint-plugin-eggache" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eggache@latest --save-dev

The plugin "eslint-plugin-eggache" was referenced from the config file in ".eslintrc » eslint-config-egg/typescript » ./index.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

core/dynamic-inject/src/QualifierImplUtil.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eggache".

(The package "eslint-plugin-eggache" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eggache@latest --save-dev

The plugin "eslint-plugin-eggache" was referenced from the config file in ".eslintrc » eslint-config-egg/typescript » ./index.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

Copy link

@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: 0

🧹 Nitpick comments (2)
core/core-decorator/src/util/QualifierUtil.ts (1)

7-10: Behavior change: Now warns instead of failing on duplicate qualifier

This change modifies the error handling in addProtoQualifier from throwing an error to logging a warning when a qualifier is already implemented. This allows the code to continue execution and will silently overwrite the existing qualifier.

While this makes the system more resilient to duplicate qualifier definitions, be cautious as it could lead to unexpected behavior if users don't notice the warning messages.

Consider adding detailed documentation about this behavior change, especially noting that:

  1. Duplicate qualifiers will be overwritten with a warning
  2. The isForceReplacement parameter can be used to suppress the warning
core/dynamic-inject/src/QualifierImplUtil.ts (1)

6-9: Behavior change: Now warns instead of failing on duplicate qualifier implementation

Similar to the change in QualifierUtil, this modification replaces error throwing with a warning when a qualifier implementation already exists. The code will continue execution and overwrite the existing implementation.

This change is consistent with the approach in QualifierUtil and makes the system more tolerant of duplicate qualifier implementations.

Consider adding a test case that verifies this new behavior works as expected:

  1. Define a qualifier implementation for an abstract class
  2. Define another implementation for the same qualifier
  3. Verify that the second implementation is used and that a warning is logged
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5b0de0e and 286b3a3.

📒 Files selected for processing (2)
  • core/core-decorator/src/util/QualifierUtil.ts (1 hunks)
  • core/dynamic-inject/src/QualifierImplUtil.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Runner-ubuntu (22)
  • GitHub Check: Runner-ubuntu (16)
  • GitHub Check: Runner-ubuntu (18)
  • GitHub Check: Runner-ubuntu (20)

@fengmk2
Copy link
Member

fengmk2 commented Apr 17, 2025

@coderabbitai 建一个 issue 跟进此 pr 会 pick 到 next 分支

Copy link

coderabbitai bot commented Apr 17, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@fengmk2 已为您创建了一个 issue,用于跟进此 PR 会被 pick 到 next 分支。issue 已经分配给您,包含了 PR 的相关信息和跟进操作的检查列表。


🏁 Script executed:

#!/bin/bash
# Create an issue to track that PR #300 will be cherry-picked to the next branch
gh issue create \
  --repo eggjs/tegg \
  --title "跟进: PR #300 需要 pick 到 next 分支" \
  --body "## 跟进事项

PR #300 \"fix: qualifier use over write\" 需要被 cherry-pick 到 next 分支。

### 相关链接
- PR: https://github.com/eggjs/tegg/pull/300
- 评论: https://github.com/eggjs/tegg/pull/300#issuecomment-2023309046

### 操作
- [ ] 将 PR #300 cherry-pick 到 next 分支
- [ ] 确认 next 分支上的修改正常工作

### 背景
PR #300 修改了 QualifierUtil 和 QualifierImplUtil 中的错误处理机制,将抛出错误改为打印警告信息。这个修改需要同步到 next 分支。

由 @fengmk2 在评论中请求创建此 issue。" \
  --assignee fengmk2

Length of output: 540


@fengmk2 已成功创建 issue 来跟进此 PR 会 pick 到 next 分支。issue 地址:#305

该 issue 已分配给您,并包含了相关 PR 信息、操作检查列表和背景说明。

@killagu
Copy link
Contributor

killagu commented Apr 17, 2025

不应该用 console,这里改成配置的模式,应用主动配置强校验的情况才抛错。

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.

3 participants