Skip to content
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

fix(cli): throw warning for duplicate systems #2325

Merged
merged 4 commits into from
Feb 27, 2024

Conversation

vmaark
Copy link
Contributor

@vmaark vmaark commented Feb 27, 2024

Resolves #2263

Throw error when systems with the same ids occur.

Copy link

changeset-bot bot commented Feb 27, 2024

🦋 Changeset detected

Latest commit: 7ee014b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@latticexyz/cli Patch
@latticexyz/world Patch
@latticexyz/dev-tools Patch
@latticexyz/store-sync Patch
@latticexyz/world-modules Patch
@latticexyz/store-indexer Patch
@latticexyz/abi-ts Patch
@latticexyz/block-logs-stream Patch
@latticexyz/common Patch
@latticexyz/config Patch
create-mud Patch
@latticexyz/ecs-browser Patch
@latticexyz/faucet Patch
@latticexyz/gas-report Patch
@latticexyz/network Patch
@latticexyz/noise Patch
@latticexyz/phaserx Patch
@latticexyz/protocol-parser Patch
@latticexyz/react Patch
@latticexyz/recs Patch
@latticexyz/schema-type Patch
@latticexyz/services Patch
@latticexyz/solecs Patch
solhint-config-mud Patch
solhint-plugin-mud Patch
@latticexyz/std-client Patch
@latticexyz/std-contracts Patch
@latticexyz/store-cache Patch
@latticexyz/store Patch
@latticexyz/utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vmaark vmaark changed the title throw warning for duplicate systems fix(cli): throw warning for duplicate systems Feb 27, 2024
if (systems.some((elem, idx) => elem.systemId === item.systemId && idx !== index)) {
throw new Error(`Duplicate system ID ${item.systemId} found in the config.`);
}
});
Copy link
Member

@holic holic Feb 27, 2024

Choose a reason for hiding this comment

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

Since we are working with objects, we could probably simplify this a bit by just checking if each item and elem are not the same (rather than their indices).

I think we could improve this error message too, something like:

Found two systems with the same system ID: {name1}, {name2}

System IDs are generated from the first 14 bytes of the name, so you may need to rename one of these systems to avoid the overlap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

improved the error message.
I think it's safer to use the idx in the context of objects, a change in the logic could easily introduce a bug where you'd be checking e.q. the equality of different objects but with the same id (and they would never equal on the object reference level)

Copy link
Member

@holic holic Feb 27, 2024

Choose a reason for hiding this comment

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

in this case, we're just trying to make sure we're comparing system IDs, but we don't want to compare to itself, so an object reference seems fine

Copy link
Member

@holic holic Feb 27, 2024

Choose a reason for hiding this comment

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

re: above code, could potentially clarify with

const overlappingSystem = systems.find(...);
if (overlappingSystem) {
  throw new Error(`Found two systems with the same system ID: ${system.name}, ${overlappingSystem.name}.\n\nSystem IDs are generated from the first 14 bytes of the name, so you may need to rename one of these systems to avoid the overlap.`);
}

@holic
Copy link
Member

holic commented Feb 27, 2024

Awesome, thanks for the quick turnaround!

Looks like there's a merge conflict, which is keeping CI from running.

@vmaark vmaark force-pushed the fix/warning-for-duplicate-system branch from 4304adb to 203d504 Compare February 27, 2024 19:41
@holic holic merged commit 8f49c27 into latticexyz:main Feb 27, 2024
10 of 11 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.

Throw warning when systems have same prefixes
2 participants