feat: remove incarnon #688

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

View File

@ -9,27 +9,40 @@ export const evolveWeaponController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
const payload = getJSONfromString(String(req.body)) as IEvolveWeaponRequest;
console.assert(payload.Action == "EWA_INSTALL");
const recipe = getRecipe(payload.Recipe)!;
addMiscItems(
inventory,
recipe.ingredients.map(x => ({ ItemType: x.ItemType, ItemCount: x.ItemCount * -1 }))
);
if (payload.Action == "EWA_INSTALL") {
addMiscItems(
inventory,
recipe.ingredients.map(x => ({ ItemType: x.ItemType, ItemCount: x.ItemCount * -1 }))
);
const item = inventory[payload.Category].find(item => item._id.toString() == (req.query.ItemId as string))!;
item.Features ??= 0;
item.Features |= EquipmentFeatures.INCARNON_GENESIS;
const item = inventory[payload.Category].find(item => item._id.toString() == (req.query.ItemId as string))!;
item.Features ??= 0;
item.Features |= EquipmentFeatures.INCARNON_GENESIS;
item.SkillTree = "0";
item.SkillTree = "0";
inventory.EvolutionProgress ??= [];
if (!inventory.EvolutionProgress.find(entry => entry.ItemType == payload.EvoType)) {
inventory.EvolutionProgress.push({
Progress: 0,
Rank: 1,
ItemType: payload.EvoType
});
inventory.EvolutionProgress ??= [];
if (!inventory.EvolutionProgress.find(entry => entry.ItemType == payload.EvoType)) {
inventory.EvolutionProgress.push({
Progress: 0,
Rank: 1,
ItemType: payload.EvoType
});
}
} else if (payload.Action == "EWA_UNINSTALL") {
addMiscItems(inventory, [
{
ItemType: recipe.resultType,
ItemCount: 1
}
]);
coderabbitai[bot] commented 2025-01-02 15:59:45 -08:00 (Migrated from github.com)
Review

💡 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 -->
const item = inventory[payload.Category].find(item => item._id.toString() == (req.query.ItemId as string))!;
item.Features! &= ~EquipmentFeatures.INCARNON_GENESIS;
} else {
throw new Error(`unexpected evolve weapon action: ${payload.Action}`);
}
await inventory.save();
@ -37,7 +50,7 @@ export const evolveWeaponController: RequestHandler = async (req, res) => {
};
interface IEvolveWeaponRequest {
Action: "EWA_INSTALL";
Action: string;
Category: WeaponTypeInternal;
Recipe: string; // e.g. "/Lotus/Types/Items/MiscItems/IncarnonAdapters/UnlockerBlueprints/DespairIncarnonBlueprint"
UninstallRecipe: "";