-
Notifications
You must be signed in to change notification settings - Fork 108
fix: should not print error when session doesn't exist #768
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
Conversation
WalkthroughThe pull request introduces modifications across four files: Changes
Sequence DiagramsequenceDiagram
participant Client
participant Session
participant FileDriver
Client->>Session: Read session data
Session->>FileDriver: Invoke Read method
FileDriver-->>Session: Return data (or empty string)
Session->>Session: Check if value is not empty
alt Value is not empty
Session->>Session: Unmarshal data
else Value is empty
Session->>Session: Skip unmarshalling
end
Session-->>Client: Return processed data or nil
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #768 +/- ##
==========================================
- Coverage 69.98% 69.96% -0.03%
==========================================
Files 213 213
Lines 18118 18119 +1
==========================================
- Hits 12680 12677 -3
- Misses 4748 4750 +2
- Partials 690 692 +2 ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
session/driver/file_test.go (1)
42-42: Update test descriptions to reflect new behaviorThe test assertions have been updated to expect
nilerrors, but the test function names and comments don't clearly indicate this new behavior. Consider adding comments to explicitly document that non-existent sessions should return empty string without error.Consider adding comments like:
func (f *FileTestSuite) TestDestroy() { + // Reading a destroyed session should return empty string without error ... } func (f *FileTestSuite) TestGc() { + // Reading an expired session should return empty string without error ... } func (f *FileTestSuite) TestRead() { + // Reading a non-existent session should return empty string without error ... }Also applies to: 61-62, 91-92
session/session.go (1)
247-253: Consider consolidating error handlingWhile the empty string check prevents unnecessary JSON unmarshaling, we're still logging errors that might be expected. Consider:
- Distinguishing between expected and unexpected errors
- Only logging unexpected errors
- Using structured logging for better error tracking
func (s *Session) readFromHandler() map[string]any { value, err := s.driver.Read(s.GetID()) - if err != nil { + if err != nil && !errors.Is(err, ErrSessionNotFound) { color.Errorln(err) return nil } var data map[string]any if value != "" { if err := s.json.Unmarshal([]byte(value), &data); err != nil { - color.Errorln(err) + color.Errorln("Failed to unmarshal session data:", err) return nil } } return data }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
session/driver/file.go(1 hunks)session/driver/file_test.go(3 hunks)session/session.go(1 hunks)
🔇 Additional comments (1)
session/driver/file.go (1)
82-82: Consider following Go idioms for "not found" cases
While removing the error helps achieve the goal of not printing errors for non-existent sessions, returning (nil, nil) for "not found" cases doesn't follow common Go idioms. Consider either:
- Following the standard Go pattern of returning
("", ErrNotFound)but handling this specific error differently in the session package, or - Adding documentation to explicitly state that this is intentional behavior
Let's check how other session drivers handle this case:
| } | ||
|
|
||
| return "", errors.SessionNotFound.Args(id) | ||
| return "", nil |
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.
Q: Does error errors.SessionNotFound need to be deleted?
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.
Good question, we can remove it.
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.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.
| Benchmark suite | Current: bb8f850 | Previous: 8afbbef | Ratio |
|---|---|---|---|
Benchmark_Fatal |
2e-7 ns/op 0 B/op 0 allocs/op |
1e-7 ns/op 0 B/op 0 allocs/op |
2 |
Benchmark_Fatal - ns/op |
2e-7 ns/op |
1e-7 ns/op |
2 |
This comment was automatically generated by workflow using github-action-benchmark.
devhaozi
left a comment
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
* correctly set cc and bcc headers (#1144) * correct the error return from SendMailJob handle (#1147) * fix: [#743] package make command generates correct code (#1151) (#1152) (cherry picked from commit 93dc8a3) * fix: [#749] The path is incorrect when publishing package files (#1157) * chore: optimize assertions for package installation (#1160) * fix: The configuredServiceProviders, publishes and publishGroups are not reset when Booting (#1162) * fix: The configuredServiceProviders, publishes and publishGroups are not reset when Booting * optimize * fix: [#738] The Orm Creating event can be triggered when the query with the Model method (#1166) * fix: [#738] The Orm Creating event can be triggered when the query with the Model method * fix tests * upgrade: v1.16.1 * fix: [#762] handle panic when using transaction (#1183) * fix: [#762] handle panic when using transaction * v1.16.2 * optimize * fix lint * fix: [#768] facades.DB will panic when migrating a new column (#1185) * fix: [#768] facades.DB will panic when migrating a new column * optimize * optimize * feat: [#770] Add a SelectRaw function for the ORM (#1186) * fix: [#770] Add a SelectRaw function for the ORM * fix: [#770] Add a SelectRaw function for the ORM * fix ci * upgrade: v1.16.3 * fix typo --------- Co-authored-by: krishan kumar <[email protected]> Co-authored-by: ALMAS <[email protected]>
* correctly set cc and bcc headers (#1144) * correct the error return from SendMailJob handle (#1147) * fix: [#743] package make command generates correct code (#1151) (#1152) (cherry picked from commit 93dc8a3) * fix: [#749] The path is incorrect when publishing package files (#1157) * chore: optimize assertions for package installation (#1160) * fix: The configuredServiceProviders, publishes and publishGroups are not reset when Booting (#1162) * fix: The configuredServiceProviders, publishes and publishGroups are not reset when Booting * optimize * fix: [#738] The Orm Creating event can be triggered when the query with the Model method (#1166) * fix: [#738] The Orm Creating event can be triggered when the query with the Model method * fix tests * upgrade: v1.16.1 * fix: [#762] handle panic when using transaction (#1183) * fix: [#762] handle panic when using transaction * v1.16.2 * optimize * fix lint * fix: [#768] facades.DB will panic when migrating a new column (#1185) * fix: [#768] facades.DB will panic when migrating a new column * optimize * optimize * feat: [#770] Add a SelectRaw function for the ORM (#1186) * fix: [#770] Add a SelectRaw function for the ORM * fix: [#770] Add a SelectRaw function for the ORM * fix ci * upgrade: v1.16.3 * fix: comand cannot be run concurrently (#1243) * fix: comand cannot be run concurrently * fix ci * fix ci * optimize * optimize * optimize * optimize * optimize global options * fix ci * upgrade v1.16.4 * optimize * optimize --------- Co-authored-by: krishan kumar <[email protected]> Co-authored-by: ALMAS <[email protected]>
* correctly set cc and bcc headers (#1144) * correct the error return from SendMailJob handle (#1147) * fix: [#743] package make command generates correct code (#1151) (#1152) (cherry picked from commit 93dc8a3) * fix: [#749] The path is incorrect when publishing package files (#1157) * chore: optimize assertions for package installation (#1160) * fix: The configuredServiceProviders, publishes and publishGroups are not reset when Booting (#1162) * fix: The configuredServiceProviders, publishes and publishGroups are not reset when Booting * optimize * fix: [#738] The Orm Creating event can be triggered when the query with the Model method (#1166) * fix: [#738] The Orm Creating event can be triggered when the query with the Model method * fix tests * upgrade: v1.16.1 * fix: [#762] handle panic when using transaction (#1183) * fix: [#762] handle panic when using transaction * v1.16.2 * optimize * fix lint * fix: [#768] facades.DB will panic when migrating a new column (#1185) * fix: [#768] facades.DB will panic when migrating a new column * optimize * optimize * feat: [#770] Add a SelectRaw function for the ORM (#1186) * fix: [#770] Add a SelectRaw function for the ORM * fix: [#770] Add a SelectRaw function for the ORM * fix ci * upgrade: v1.16.3 * fix: comand cannot be run concurrently (#1243) * fix: comand cannot be run concurrently * fix ci * fix ci * optimize * optimize * optimize * optimize * optimize global options * fix ci * upgrade v1.16.4 * fix: [#807] queue.Shutdown doesn't stop the queue as expected (#1252) * fix: [#807] queue.Shutdown doesn't stop the queue as expected * optimize * upgrade: v1.16.5 * fix * Update queue/worker_test.go Co-authored-by: Copilot <[email protected]> * optimize --------- Co-authored-by: krishan kumar <[email protected]> Co-authored-by: ALMAS <[email protected]> Co-authored-by: Copilot <[email protected]>
* correctly set cc and bcc headers (#1144) * correct the error return from SendMailJob handle (#1147) * fix: [#743] package make command generates correct code (#1151) (#1152) (cherry picked from commit 93dc8a3) * fix: [#749] The path is incorrect when publishing package files (#1157) * chore: optimize assertions for package installation (#1160) * fix: The configuredServiceProviders, publishes and publishGroups are not reset when Booting (#1162) * fix: The configuredServiceProviders, publishes and publishGroups are not reset when Booting * optimize * fix: [#738] The Orm Creating event can be triggered when the query with the Model method (#1166) * fix: [#738] The Orm Creating event can be triggered when the query with the Model method * fix tests * upgrade: v1.16.1 * fix: [#762] handle panic when using transaction (#1183) * fix: [#762] handle panic when using transaction * v1.16.2 * optimize * fix lint * fix: [#768] facades.DB will panic when migrating a new column (#1185) * fix: [#768] facades.DB will panic when migrating a new column * optimize * optimize * feat: [#770] Add a SelectRaw function for the ORM (#1186) * fix: [#770] Add a SelectRaw function for the ORM * fix: [#770] Add a SelectRaw function for the ORM * fix ci * upgrade: v1.16.3 * fix: comand cannot be run concurrently (#1243) * fix: comand cannot be run concurrently * fix ci * fix ci * optimize * optimize * optimize * optimize * optimize global options * fix ci * upgrade v1.16.4 * fix: [#807] queue.Shutdown doesn't stop the queue as expected (#1252) * fix: [#807] queue.Shutdown doesn't stop the queue as expected * optimize * upgrade: v1.16.5 * fix * Update queue/worker_test.go Co-authored-by: Copilot <[email protected]> * optimize --------- Co-authored-by: krishan kumar <[email protected]> Co-authored-by: ALMAS <[email protected]> Co-authored-by: Copilot <[email protected]>
📑 Description
Summary by CodeRabbit
New Features
Bug Fixes
Readmethod, which now returns no error for non-existent sessions.Tests
✅ Checks