-
Notifications
You must be signed in to change notification settings - Fork 54
Error handling for malformed session file #38
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
Error handling for malformed session file #38
Conversation
int _sessionId; | ||
int _lastPing; | ||
|
||
// Initialize as 0 but will get parsed to real values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@christopherfujino i wanted to avoid using the late keyword here for these 2 variables, let me know what you think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're calculating this within the private constructor, can we not calculate it in the factory?
And if not, can we go the other way and get rid of the factory altogether?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an instance method _refreshSessionData()
that will be used to calculate those two ints so it can't be used within the factory constructor body.
But I agree with removing the factory constructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why using avoid late
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was referring to the usage guide where it says to avoid late
where possible. I also have used it in other parts of the package that could probably be refactored once this package is stable and being used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the link you shared:
AVOID late variables if you need to check whether they are initialized
I think using late
is fine if a variable should definitely be initialized before it's read. While I believe avoiding late
by default is good, I think initializing variables with placeholder values has more (potential) problems. If we intend for a variable to get "properly" initialized before first read, then reading it before that initialization should throw, and late
does this for us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great point, I also agree with that. I'll revert that back to use late
again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nit
Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.0 to 3.5.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@8f4b7f8...8e5e7e5) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Fixes: #20
Adding functionality here to not crash the dart process incase the user somehow edited the
.dart/session.json
file that contains information about sessions across all dart related tooling for Google Analytics. Below is an example of what a valid session file looks likesession_id
: the current session valuelast_ping
: the timestamp for the last event that was sentBoth values above are milliseconds since epoch time.
session_id
will get updated to belast_ping
if the time difference between the two is greater than the duration allotted for a session (30 mins atm)If the user somehow changes the contents of this file though, any dart and flutter related tool will also crash. As a result, this PR aims to detect the file has been malformed, recreate it, and parse that file again.