feat: remove incarnon #688

Merged
Sainan merged 1 commits from remove-incarnon into main 2025-01-03 00:06:34 -08:00
Owner

Closes #673

Closes #673
coderabbitai[bot] commented 2025-01-02 15:57:09 -08:00 (Migrated from github.com)
Author
Owner

Walkthrough

The pull request modifies the evolveWeaponController in the src/controllers/api/evolveWeaponController.ts file. The primary change involves enhancing the function's control flow to handle two distinct actions: "EWA_INSTALL" and "EWA_UNINSTALL". For the "EWA_INSTALL" action, the function manages inventory additions, item feature updates, skill tree configuration, and evolution progress. The "EWA_UNINSTALL" action allows for removing the Incarnon upgrade and returning the Genesis Adapter to the inventory. If an unexpected action is encountered, the function now throws an error. The interface IEvolveWeaponRequest has been updated to use a more flexible string type for the Action property instead of a specific literal type.

Assessment against linked issues

Objective Addressed Explanation
Remove Incarnon upgrade and return Genesis Adapter [#673]
Ensure no refund of Duviri resources during removal [#673]

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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.

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.
<!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- walkthrough_start --> ## Walkthrough The pull request modifies the `evolveWeaponController` in the `src/controllers/api/evolveWeaponController.ts` file. The primary change involves enhancing the function's control flow to handle two distinct actions: "EWA_INSTALL" and "EWA_UNINSTALL". For the "EWA_INSTALL" action, the function manages inventory additions, item feature updates, skill tree configuration, and evolution progress. The "EWA_UNINSTALL" action allows for removing the Incarnon upgrade and returning the Genesis Adapter to the inventory. If an unexpected action is encountered, the function now throws an error. The interface `IEvolveWeaponRequest` has been updated to use a more flexible string type for the `Action` property instead of a specific literal type. ## Assessment against linked issues | Objective | Addressed | Explanation | |-----------|-----------|-------------| | Remove Incarnon upgrade and return Genesis Adapter [#673] | ✅ | | | Ensure no refund of Duviri resources during removal [#673] | ✅ | | <!-- walkthrough_end --> <!-- internal state start --> <!-- FAHghAtBAEAqAWBLAztF0CGA7TBXALgPYQDmAplmQE4b5kAm0AxoQLasX4Bc0ADldEIAjAFZkm+RADcyqIQE9mhetQxChifADoMiaFAB8wY+CjGAxOegAFAErQ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Ss0M5idVG4ZD6Qg3FJQ7jroX7OToVh9KSd74VJJpEu9TrED8CJAjIUkkWtbAMHIbnoAcgh8beEh4WQOY4e5RGLqG0aJrTMcppmuaFtJTQSfoO7DWNU0ErOWlO26k5GawZmiBguXUnSK1VUUqbGME2wxwAeTHcaAHFhrHYaHGEhw9MeQWXjePnGd5nX4cdUG9XoQgrVySLaCBFXG2aXcPh2MgAA8jQkGJIZ8UJkGxhZcfznBo0IQofxVqgssySlqVTdpDPrxuaX1rAYeAQTYU0MGnp8eQO68RSQeMvS3SNKh8EUL0lOE4aqMc9SGNsYI2/wPTLuoeJRw24ZxgoWTLUYV53gwSDG5NKkkFWKpkPkaaAJYUYTTNhjBaS42qYGtKzLwR5VDPWAcqCI8gjSyz8H3VMiYBC/yEG8GEzQaCWhkrPaALc26rn4lYQSPg6AnjBgzBYKgmA+FcFVLAqBq5T1ZjSVm3ghB5TNJwZe8lgAwAALJkEuMoSCIU2hpwOkdE6PAt7dx4JAtG5tMb3xMn0R+z8g5n1UpfPI18QhhD0oAJMJoBaOMjwF6SxlSGPBCY8MjjT7n1os5LA1jb4eLMthXCrlrK2TIhRPxTkNJMQiYRDiXFFI8T4tI1C6EtydEoQeMSQEYhnk4GBCCUkYK1EfGoDQSE3yZI/Eodgmhxo9GQONQIUhBiFAYONF6rhwjrlAJuaAAAmKYGAGBCHiEweIEwJgAE45n4iYPifEGAACMEwACsAAWfE2zhlzImNMjA2yhDbN2YcjAwz8QoTQvUs8TSWltOKmQLp9BxrbluUAA== --> <!-- internal state end --> <!-- tips_start --> --- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <details> <summary>🪧 Tips</summary> ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - 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](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR. ([Beta](https://docs.coderabbit.ai/early-access#beta)) - `@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. ### Documentation and Community - Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements. </details> <!-- tips_end -->
coderabbitai[bot] (Migrated from github.com) reviewed 2025-01-02 15:59:46 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment
Author
Owner

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/controllers/api/evolveWeaponController.ts (2)

14-18: Consider avoiding magic strings for action checks.
Currently, the code compares payload.Action to "EWA_INSTALL" directly. It’s easy to introduce errors or typos with raw strings. A more robust approach would define a union type or an enum for possible action values.

- if (payload.Action == "EWA_INSTALL") {
+ if (payload.Action === ACTIONS.EWA_INSTALL) {

53-53: Reintroduce stricter type for the Action field.
Changing Action to string reduces type safety and can lead to unexpected actions slipping through. Use a union or an enum to keep compile-time validation of valid actions.

- Action: string;
+ Action: 'EWA_INSTALL' | 'EWA_UNINSTALL';
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff4b1e5c29 and 28aedbfcf6.

📒 Files selected for processing (1)
  • src/controllers/api/evolveWeaponController.ts (1 hunks)
🔇 Additional comments (2)
src/controllers/api/evolveWeaponController.ts (2)

24-33: Revisit SkillTree and EvolutionProgress initialization.
While this logic seems functional, ensure that defaulting item.SkillTree = "0" is intended for all newly evolved items. Similarly, check whether adding an entry to EvolutionProgress is always desirable.


34-45: Avoid repeated magic strings and validate item existence.
This block closely mirrors the install logic. Consider abstracting shared logic to a helper function or at least unify string checks with an enum or union type. Also, verify inventory[payload.Category].find(...)! does not fail.
[refactor_suggestion_good_to_have, verify]

**Actionable comments posted: 1** <details> <summary>🧹 Nitpick comments (2)</summary><blockquote> <details> <summary>src/controllers/api/evolveWeaponController.ts (2)</summary><blockquote> `14-18`: **Consider avoiding magic strings for action checks.** Currently, the code compares `payload.Action` to `"EWA_INSTALL"` directly. It’s easy to introduce errors or typos with raw strings. A more robust approach would define a union type or an enum for possible action values. ```diff - if (payload.Action == "EWA_INSTALL") { + if (payload.Action === ACTIONS.EWA_INSTALL) { ``` --- `53-53`: **Reintroduce stricter type for the Action field.** Changing `Action` to `string` reduces type safety and can lead to unexpected actions slipping through. Use a union or an enum to keep compile-time validation of valid actions. ```diff - Action: string; + Action: 'EWA_INSTALL' | 'EWA_UNINSTALL'; ``` </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: .coderabbit.yaml** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between ff4b1e5c29a4cb23cbd173b4ab99d7d45fdadbb1 and 28aedbfcf66997c77a165474296cfa4b44796a27. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/controllers/api/evolveWeaponController.ts` (1 hunks) </details> <details> <summary>🔇 Additional comments (2)</summary><blockquote> <details> <summary>src/controllers/api/evolveWeaponController.ts (2)</summary> `24-33`: **Revisit SkillTree and EvolutionProgress initialization.** While this logic seems functional, ensure that defaulting `item.SkillTree = "0"` is intended for all newly evolved items. Similarly, check whether adding an entry to `EvolutionProgress` is always desirable. --- `34-45`: **Avoid repeated magic strings and validate item existence.** This block closely mirrors the install logic. Consider abstracting shared logic to a helper function or at least unify string checks with an enum or union type. Also, verify `inventory[payload.Category].find(...)!` does not fail. [refactor_suggestion_good_to_have, verify] </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
@ -33,0 +38,4 @@
ItemCount: 1
}
]);
coderabbitai[bot] (Migrated from github.com) commented 2025-01-02 15:59:45 -08:00
Author
Owner

💡 Codebase verification

Based on the analysis of the codebase, I can now provide the final response:

The non-null assertion is risky and should be handled properly

Looking at the error handling patterns in the codebase, particularly in gildWeaponController.ts, there's a consistent pattern of checking for item existence and throwing descriptive errors. The current use of non-null assertion (!) in evolveWeaponController.ts could lead to runtime errors if the item is not found.

The suggested changes are:

  • Add proper error handling before accessing the item
  • Maintain consistency with other controllers like gildWeaponController.ts that properly validate item existence
  • Throw a descriptive error message that helps with debugging
- const item = inventory[payload.Category].find(item => item._id.toString() == (req.query.ItemId as string))!;
+ const item = inventory[payload.Category].find(item => item._id.toString() == (req.query.ItemId as string));
+ if (!item) {
+   throw new Error(`Item with ID ${req.query.ItemId} not found in category ${payload.Category}`);
+ }
🔗 Analysis chain

Verify item existence before using the non-null assertion operator.
Using ! on find(...) can cause a runtime error if find returns undefined. Consider throwing a descriptive error or gracefully handling the missing item.

- const item = inventory[payload.Category].find(item => item._id.toString() == (req.query.ItemId as string))!;
+ const item = inventory[payload.Category].find(
+   (item) => item._id.toString() === (req.query.ItemId as string)
+ );
+ if (!item) {
+   throw new Error("Item not found in inventory");
+ }

Let me gather more information about the codebase to verify the concern.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Search for similar patterns of non-null assertions with find() in the codebase
ast-grep --pattern 'find($_) !'

# Look for error handling patterns in the controller
rg -A 5 "throw new" "src/controllers/api/"

# Check the evolveWeaponController.ts file content
cat src/controllers/api/evolveWeaponController.ts

Length of output: 12272

_:bulb: Codebase verification_ Based on the analysis of the codebase, I can now provide the final response: **The non-null assertion is risky and should be handled properly** Looking at the error handling patterns in the codebase, particularly in `gildWeaponController.ts`, there's a consistent pattern of checking for item existence and throwing descriptive errors. The current use of non-null assertion (`!`) in `evolveWeaponController.ts` could lead to runtime errors if the item is not found. The suggested changes are: - Add proper error handling before accessing the item - Maintain consistency with other controllers like `gildWeaponController.ts` that properly validate item existence - Throw a descriptive error message that helps with debugging ```diff - const item = inventory[payload.Category].find(item => item._id.toString() == (req.query.ItemId as string))!; + const item = inventory[payload.Category].find(item => item._id.toString() == (req.query.ItemId as string)); + if (!item) { + throw new Error(`Item with ID ${req.query.ItemId} not found in category ${payload.Category}`); + } ``` <details> <summary>🔗 Analysis chain</summary> **Verify item existence before using the non-null assertion operator.** Using `!` on `find(...)` can cause a runtime error if `find` returns `undefined`. Consider throwing a descriptive error or gracefully handling the missing item. ```diff - const item = inventory[payload.Category].find(item => item._id.toString() == (req.query.ItemId as string))!; + const item = inventory[payload.Category].find( + (item) => item._id.toString() === (req.query.ItemId as string) + ); + if (!item) { + throw new Error("Item not found in inventory"); + } ``` --- Let me gather more information about the codebase to verify the concern. </details> <details> <summary>🏁 Scripts executed</summary> The following scripts were executed for the analysis: Error: No shell scripts found --- Script: ```shell #!/bin/bash # Search for similar patterns of non-null assertions with find() in the codebase ast-grep --pattern 'find($_) !' # Look for error handling patterns in the controller rg -A 5 "throw new" "src/controllers/api/" # Check the evolveWeaponController.ts file content cat src/controllers/api/evolveWeaponController.ts ``` Length of output: 12272 </details> <!-- This is an auto-generated comment by CodeRabbit -->
Sign in to join this conversation.
No description provided.