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

add helping log when trying to access an entity that does not exist #1712

Closed
wants to merge 1 commit into from

Conversation

mockersf
Copy link
Member

Noticed in #1707

This adds a warn log when accessing an entity that doesn't exist, and the reason (doesn't exist yet or already despawned)

@alice-i-cecile alice-i-cecile added C-Code-Quality A section of code that is hard to understand or change A-ECS Entities, components, systems, and events labels Mar 20, 2021
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

This is useful and your implementation seems sensible.

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Mar 20, 2021
let location = match self.entities.get(entity) {
Ok(entity_location) => entity_location,
Err(err) => {
warn!("Error getting entity {:?}: {:?}", entity, err,);
Copy link

Choose a reason for hiding this comment

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

Suggested change
warn!("Error getting entity {:?}: {:?}", entity, err,);
warn!("Error getting entity {:?}: {:?}", entity, err);

I think this trailing comma is here by mistake?

let location = match self.entities.get(entity) {
Ok(entity_location) => entity_location,
Err(err) => {
warn!("Error getting entity {:?}: {:?}", entity, err,);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think warn! is a too strong log level. The user may very well just not care about if the entity exists or not. I think it would be better to return Result<EntityRef, GetEntityError> where GetEntityError has a Debug implementation that shows all this information.

Copy link
Member

Choose a reason for hiding this comment

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

I agree. This method feels too "low level" and could be called in too many different situations to call this case a warning / make it unrecoverable. I'd prefer to preserve the simplicity of the Option return type (like std's collection types) if possible, but if we really need to expose multiple "failure" states, it probably makes sense to just return an error here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I... can't remember why I wanted a warn here :(
I could weakly argue that the user should not ignore this, but the Option already achieve that.

For the error reason, I think knowing it can help the user debug issues looking at the log but is not very useful from the code. Should I change the log to info or debug?

Copy link
Member

Choose a reason for hiding this comment

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

I honestly don't want to log at all here. If some subset of users need to care about the various reasons an entity might not exist, then imo we need to return a Result here.

@mockersf mockersf closed this Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants