-
Notifications
You must be signed in to change notification settings - Fork 129
chore(rivetkit): log close code when client ws closes #3361
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
chore(rivetkit): log close code when client ws closes #3361
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
PR Review: Log close code when client ws closesSummaryThis PR improves error messaging when a WebSocket connection closes by including the close code and reason in the error message passed to the onOpen promise rejection. The change moves the promise rejection after the Code Quality ✅Positives:
Potential Issues
|
4b3360a to
b33ce24
Compare
fb92df2 to
31223d5
Compare
Code ReviewSummaryThis PR improves error messaging when a WebSocket connection closes by including the close code and reason in the rejected promise. This is a valuable debugging improvement that provides more context about connection failures. Positive Changes✅ Enhanced Error Messages: Including Potential Issues & Suggestions1. Inconsistent Error Handling PatternThe error handling for
Suggestion: Consider applying similar detailed error messaging to the in-flight actions for consistency: const disconnectError = new Error(
`websocket ${wasClean ? "closed" : "lost"} with code ${closeEvent.code}: ${closeEvent.reason || "no reason provided"}`
);2. Undefined Values in Node.jsThe comment on line 566 mentions that CloseEvent properties might be undefined in Node.js. The error message should handle this gracefully: Suggestion: this.#onOpenPromise.reject(
new Error(
`websocket closed with code ${closeEvent.code ?? "unknown"}: ${closeEvent.reason || "no reason provided"}`,
),
);This prevents the error message from showing "undefined" when these properties aren't available. 3. Missing Test CoverageNo tests were found for this WebSocket close handling logic. Given that this is critical error handling code: Suggestion: Consider adding tests that verify:
4. Minor: Error Message ConsistencyThe structured log uses lowercase "socket closed" (line 582) while other patterns in the codebase appear to use lowercase for log messages. The error message should probably follow a similar pattern. Current: Non-Blocking Observations
Overall AssessmentThis is a good quality improvement that enhances debuggability. The main suggestions are around handling edge cases (undefined values) and maintaining consistency across similar error paths. None of the issues are blockers, but addressing them would make the code more robust. Recommendation: ✅ Approve with minor suggestions for improvement |
31223d5 to
b41010e
Compare
b33ce24 to
2b8185b
Compare
Code ReviewSummaryThis PR improves error messaging when a WebSocket connection closes by including the close code and reason in the error message. The change is small but valuable for debugging. Positive Aspects✅ Better error visibility: Including Code Quality ObservationsError Message Format `websocket closed with code ${closeEvent.code}: ${closeEvent.reason}`This is good, though consider that const code = closeEvent.code ?? 'unknown';
const reason = closeEvent.reason ?? 'no reason provided';
this.#onOpenPromise.reject(
new Error(`websocket closed with code ${code}: ${reason}`),
);Comparison with Similar Code const disconnectError = new Error(
wasClean ? "Connection closed" : "Connection lost",
);Consider whether the open promise rejection should also differentiate between clean and unclean closes for consistency. Minor Suggestions
Test CoverageConsider adding or updating tests that verify:
Overall AssessmentThis is a solid improvement to error reporting. The change is well-scoped and will make debugging WebSocket issues easier. The only concern is the potential for Recommendation: ✅ Approve with minor suggestions for handling undefined values. |
Code ReviewSummaryThis PR improves error messaging when a WebSocket connection closes by including the close code and reason in the error message passed to the onOpen promise rejection. This is a valuable debugging enhancement that provides better context about connection failures. Positive Changes
Issues and Recommendations1. Handling Undefined Values in Node.jsLocation: rivetkit-typescript/packages/rivetkit/src/client/actor-conn.ts:576 The comment at line 566-568 notes that CloseEvent properties may be undefined in Node.js environments. The current error message could result in 'websocket closed with code undefined: undefined' Recommendation: Add fallback values to handle undefined gracefully using nullish coalescing and logical OR operators for code and reason respectively. 2. Consider Consistency with In-Flight Actions Error PatternLocation: Compare lines 574-577 with lines 600-602 The error handling for actionsInFlight uses the wasClean flag to differentiate between Connection closed vs Connection lost. Consider whether the open promise rejection should follow a similar pattern. This is optional but would maintain consistency across error paths. Test CoverageNo tests were found for this WebSocket close handling logic. Consider adding test coverage for:
Performance and Security
Overall AssessmentThis is a quality improvement that enhances debuggability. The main concern is handling the undefined case in Node.js environments to avoid confusing error messages. Otherwise, the change is solid. Recommendation: Approve with suggestion to handle undefined values Review generated by Claude Code |
b41010e to
ed48aff
Compare
2b8185b to
78f7198
Compare
Code ReviewThis is a small but useful improvement that enhances error messages when WebSocket connections close. Here's my analysis: ✅ Positive Aspects
💡 Suggestions for Improvement
export class WebSocketClosedError extends ActorClientError {
constructor(
public readonly code: number,
public readonly reason: string,
) {
super(`websocket closed with code ${code}: ${reason}`);
}
}This would make the error more type-safe and easier to handle by consumers.
new Error(
`websocket closed with code ${closeEvent.code ?? 'unknown'}: ${closeEvent.reason ?? 'no reason provided'}`,
)
🔍 No Issues Found
📊 Impact
✅ RecommendationApprove with minor suggestions. This is a solid improvement that will make debugging WebSocket connection issues much easier. The suggestions above are optional enhancements, not blockers. The change aligns well with the related PR #3360 which also improves logging for operational visibility. |
Code ReviewSummaryThis PR improves error messages when a WebSocket connection closes by including the close code and reason in the rejection error. This is a helpful enhancement for debugging connection issues. Positive Observations✅ Better Error Messages: The change provides much more actionable information when debugging WebSocket connection failures. Including ✅ Logical Reordering: Moving the promise rejection after extracting the ✅ Follows Conventions: The commit message follows the repository's conventional commit format ( ✅ Consistent with Existing Logging: The close code and reason are already being logged in the structured log at line 583-584, so including them in the error message maintains consistency. Potential Issues & Suggestions1. Undefined Property Handling (Minor)At line 569-570, there's a comment noting that CloseEvent properties "will be undefined" in NodeJS. The new error message at line 576 could potentially display `websocket closed with code ${closeEvent.code}: ${closeEvent.reason}`Suggestion: Consider providing fallback values: `websocket closed with code ${closeEvent.code ?? 'unknown'}: ${closeEvent.reason ?? 'no reason provided'}`This would make error messages more informative across all environments (browser and NodeJS). 2. Unused Variable (Minor)The Suggestion: Consider moving the Testing Considerations
Performance & Security✅ No Performance Concerns: The change is minimal and doesn't introduce any performance overhead. ✅ No Security Concerns: The change only affects error messages and logging - no security implications. VerdictApproved with Minor Suggestions ✅ This is a solid quality-of-life improvement for debugging. The only suggestion is to handle potentially undefined close codes/reasons more gracefully, especially given the comment at line 568 that explicitly mentions these properties can be undefined in NodeJS environments. The change is small, focused, and improves observability - exactly what a good chore commit should do. Location References:
|
78f7198 to
95ffd87
Compare
ed48aff to
a0b95ae
Compare
Code ReviewSummaryThis PR improves error messaging when a WebSocket connection closes by including the close code and reason in the error message. This is a small but valuable change for debugging connection issues. Positive Observations
SuggestionsMinor: Error Message Consistency Minor: Handling Undefined Values Consider adding a fallback with nullish coalescing for default values or conditionally include the details only when they exist. Test CoverageI didn't find specific unit tests for the handleOnClose method in actor-conn.ts. While driver tests exist (driver-memory.test.ts, driver-engine.test.ts), they may not specifically test close event handling with various close codes. Recommendation: Consider adding test cases that verify:
Security and Performance
Overall AssessmentLGTM with minor suggestions - This is a good incremental improvement for developer experience. The suggestions above are optional refinements that could make the error handling more robust, especially in the NodeJS environment mentioned in the comments. The change is:
|
a0b95ae to
78391b5
Compare
95ffd87 to
b462d64
Compare
PR Review: Log close code when client ws closesSummaryThis PR improves error reporting by including the WebSocket close code and reason in the error message when the connection closes before the open promise resolves. This is a small but valuable improvement for debugging connection issues. Code Quality ✅Positives:
Observations:
Potential IssuesMinor - Error message format consistency: Minor - Undefined close code handling: // Possible output: "websocket closed with code undefined: undefined"Consider adding a fallback: this.#onOpenPromise.reject(
new Error(
closeEvent.code \!== undefined
? `websocket closed with code ${closeEvent.code}: ${closeEvent.reason || 'no reason provided'}`
: "websocket closed before opening"
),
);Or simply check if the properties exist before including them in the message. Security Considerations ✅No security concerns. The close code and reason are standard WebSocket protocol values. Performance Considerations ✅Negligible impact - just string interpolation. Test Coverage
|
Code ReviewSummaryThis PR improves error diagnostics by including the close code and reason in the error message when a WebSocket connection fails to open. The change moves the promise rejection to after extracting the Positive Aspects ✓
ObservationsCode QualityThe implementation is clean and straightforward. The error message format follows a clear pattern: `websocket closed with code ${closeEvent.code}: ${closeEvent.reason}`Potential Edge CasesConsider these scenarios where
Suggestion: Consider adding a fallback for when these properties are undefined: const code = closeEvent.code ?? 'unknown';
const reason = closeEvent.reason ?? 'no reason provided';
this.#onOpenPromise.reject(
new Error(`websocket closed with code ${code}: ${reason}`)
);This would prevent error messages like "websocket closed with code undefined: undefined" in environments where CloseEvent properties aren't available. Type SafetyThe
Test CoverageNo test changes were included. Consider adding a test case to verify:
Minor Style NotesThe error message follows good practices by being descriptive, though you might consider:
RecommendationApprove with suggestions. The core change is solid and improves debugging. The edge case handling for undefined properties would make it more robust, but isn't blocking if you've verified the CloseEvent properties are always populated in your environment. Great work on improving observability! 🔍 |
Merge activity
|

No description provided.