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

Refactor clean up logger #482

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

jdabapo
Copy link
Contributor

@jdabapo jdabapo commented Mar 24, 2025

Refactor typing on playByPlay logger to reduce amount of code reproduction. however, caused some initial bugs, still working on this. wanted to keep this branch open just to see if you were open to this, as this is somewhat big? And doing this would imply you would want more changes to typing for the logger, which could cause issues if not done correctly

Copy link
Member

@dumbmatter dumbmatter left a comment

Choose a reason for hiding this comment

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

Less repetitive code would definitely be welcome, just need to make sure the TypeScript types don't get worse :)

Also if you hadn't noticed already... game sim code is probably the worst code in the game. I think two reasons... it's the oldest part of the codebase, and I didn't abstract it well enough when making other sports so often fixing things needs to be done 4 times! There's been a little improvement over the years, but it's still not great.

@jdabapo jdabapo requested a review from dumbmatter March 27, 2025 00:43
@jdabapo
Copy link
Contributor Author

jdabapo commented Mar 27, 2025

Addressed comments, and made a decent amount of changes to the types... is a larger PR, and I didn't see any pre-existing tests for these changes. If needed I can try and write some tests for the logger and check if the functionality is all there?

});
fgMissLogType = g.get("threePointers") ? "missTp" : "missTpFake";
} else {
throw new Error(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably should not crash the browser if log doesnt exist... maybe better to just do console.warn?

Copy link
Member

Choose a reason for hiding this comment

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

It's actually good because people will notice and it'll get fixed quick. Console messages will get ignored, but could indicate bugs.

For stuff like this I do throw new Error("Should never happen"); so it's not wasting bytes on custom error messages that are likely never displayed. The error in the console (or in my error logger) will include the file and line number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay sounds good, and quick question, is storage not very readily available for error logging? Is that a design constraint to keep in mind when writing new code/logs?

Copy link
Member

Choose a reason for hiding this comment

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

That's not about storage, it's about bundle size. Of course it's a very small difference, probably doesn't matter! But it's also about not having to spend mental energy on writing nice error messages for a case like "this is never going to happen, and maybe I'm just writing this to tell TypeScript that it's never going to happen".

Overall, I guess it's just personal preference and consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting! I think its a bit different at work, where we write a ton of logs and description in logs. I think its also because this is primarily a solo dev project, as opposed to one where there's multiple teams working on multiple repositories. But good to know!

});
fgMissLogType = g.get("threePointers") ? "missTp" : "missTpFake";
} else {
throw new Error(
Copy link
Member

Choose a reason for hiding this comment

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

It's actually good because people will notice and it'll get fixed quick. Console messages will get ignored, but could indicate bugs.

For stuff like this I do throw new Error("Should never happen"); so it's not wasting bytes on custom error messages that are likely never displayed. The error in the console (or in my error logger) will include the file and line number.

@jdabapo jdabapo requested a review from dumbmatter March 30, 2025 03:18
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.

2 participants