-
Notifications
You must be signed in to change notification settings - Fork 715
fix: On cancel query undefined error shown on UI #4842
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 enhancements to the Changes
Possibly related PRs
Suggested reviewers
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 (
|
0887123 to
35aff79
Compare
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: 2
🧹 Outside diff range and nitpick comments (3)
web/src/composables/useLogs.ts (3)
Line range hint
1267-1275: Refactor Error Handling to Reduce RedundancyThe error handling code between lines 1267-1275 is similar to other parts of the codebase. Consider creating a utility function to handle errors uniformly, reducing code duplication and improving maintainability.
You could create a function like
handleError:function handleError(err) { let errorMsg = ''; let errorDetail = ''; let trace_id = ''; if (err.response != undefined) { errorMsg = err.response?.data?.error || err.response?.data?.message || ''; errorDetail = err.response?.data?.error_detail || ''; trace_id = err.response?.data?.trace_id || ''; } else { errorMsg = err?.message || ''; trace_id = err?.trace_id || ''; } return { errorMsg, errorDetail, trace_id }; }Then replace the error handling code:
- if (err.response != undefined) { - searchObj.data.errorMsg = err.response?.data?.error || err.response?.data?.message || ""; - if (err.response.data.hasOwnProperty("error_detail")) { - searchObj.data.errorDetail = err.response.data.error_detail; - } - if (err.response.data.hasOwnProperty("trace_id")) { - trace_id = err.response.data?.trace_id; - } - } else { - searchObj.data.errorMsg = err.message; - if (err.hasOwnProperty("trace_id")) { - trace_id = err?.trace_id; - } - } + const { errorMsg, errorDetail, trace_id } = handleError(err); + searchObj.data.errorMsg = errorMsg; + searchObj.data.errorDetail = errorDetail;🧰 Tools
🪛 Biome
[error] 1268-1268: Do not access Object.prototype method 'hasOwnProperty' from target object.
It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.(lint/suspicious/noPrototypeBuiltins)
Line range hint
1285-1290: Avoid Overwriting Error MessagesAt line 1285,
searchObj.data.errorMsgis reassigned inside theif (err?.request?.status >= 429)block, potentially overwriting the error message set earlier. Ensure this reassignment is intentional or consider consolidating the error message assignments to prevent loss of information.Consider adjusting the code:
if (err?.request?.status >= 429) { notificationMsg.value = err?.response?.data?.message; - searchObj.data.errorMsg = err?.response?.data?.message || ""; searchObj.data.errorDetail = err?.response?.data?.error_detail; }Or, if you need to update
searchObj.data.errorMsg, ensure it doesn't unintentionally overwrite important messages.
2341-2344: Simplify Optional Chaining UsageIn lines 2341-2344, you can simplify the assignments using optional chaining to make the code cleaner.
Refactored code:
if (err?.request?.status >= 429) { notificationMsg.value = err?.response?.data?.message || ""; searchObj.data.errorMsg = err?.response?.data?.message || ""; searchObj.data.errorDetail = err?.response?.data?.error_detail || ""; }This removes unnecessary lines and uses the
||operator to provide default values.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- web/src/composables/useLogs.ts (4 hunks)
- web/src/plugins/logs/Index.vue (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
web/src/plugins/logs/Index.vue (1)
248-250: Improved error handling and securityGreat improvements in this section:
- The use of optional chaining (
?.) enhances code robustness by safely accessing potentially undefined properties.- Utilizing
SanitizedHtmlRendererfor displaying HTML content is a excellent security practice, helping to prevent XSS attacks.- The error message display logic has been refined and simplified, improving readability and maintainability.
These changes contribute to a more stable and secure application.
d80f2c1 to
2c678cd
Compare
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
🧹 Outside diff range and nitpick comments (2)
web/src/composables/useLogs.ts (2)
2310-2311: Consider implementing a centralized error handling functionThe TODO comment suggests creating a
handleErrorfunction to consolidate error handling logic. This is a good idea that could improve code maintainability and consistency across the application.Would you like assistance in designing and implementing the
handleErrorfunction? This could involve:
- Identifying common error handling patterns in the current code.
- Designing a flexible function signature that can handle various error scenarios.
- Implementing the function with proper TypeScript typing.
- Updating existing error handling code to use the new function.
2319-2323: Comprehensive error handling improvementsThese changes enhance the error handling in the
getPaginatedDatafunction by:
- Using optional chaining (
?.) to safely access nested properties.- Providing fallback values with the
||operator.- Setting detailed error information on the
searchObj.dataobject.These improvements make the error handling more robust and consistent with the changes seen earlier in the file.
Once the
handleErrorfunction mentioned in the TODO comment is implemented, consider refactoring this error handling code to use that centralized function. This would further improve consistency and maintainability across the application.Example refactor (pseudo-code):
const { errorMsg, errorDetail, trace_id } = handleError(err); searchObj.data.errorMsg = errorMsg; searchObj.data.errorDetail = errorDetail; searchObj.data.errorCode = err?.response?.data?.code || "";Also applies to: 2329-2330, 2335-2338, 2347-2350
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- web/src/composables/useLogs.ts (4 hunks)
- web/src/plugins/logs/Index.vue (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- web/src/plugins/logs/Index.vue
🧰 Additional context used
📓 Learnings (1)
web/src/composables/useLogs.ts (1)
Learnt from: omkarK06 PR: openobserve/openobserve#4842 File: web/src/composables/useLogs.ts:2332-2332 Timestamp: 2024-10-19T08:47:15.694Z Learning: Using `||` to provide default values when handling potentially undefined values, such as `err?.response?.data?.code || ""`, is acceptable and works correctly in `web/src/composables/useLogs.ts`.
🪛 ast-grep
web/src/composables/useLogs.ts
[warning] 2316-2316: The application creates a database connection with an empty password. This can lead to unauthorized access by either an internal or external malicious actor. To prevent this vulnerability, enforce authentication when connecting to a database by using environment variables to securely provide credentials or retrieving them from a secure vault or HSM (Hardware Security Module).
Context: "Error while processing histogram request."
Note: [CWE-287] Improper Authentication. [REFERENCES]
- https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
🔇 Additional comments (2)
web/src/composables/useLogs.ts (2)
1267-1270: Improved error handling with optional chaining and fallbacksThe changes in this segment enhance the error handling by using optional chaining (
?.) and providing fallback values with the||operator. This approach makes the code more robust by gracefully handling potential undefined values in the error response structure.
1288-1288: Consistent error handling for rate-limiting scenariosThis change applies the same improved error handling pattern (optional chaining and fallback value) to the specific case of HTTP 429 errors. It maintains consistency with the earlier improvements and ensures a proper error message is set even if the response structure is unexpected.
2c678cd to
685a19c
Compare
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
🧹 Outside diff range and nitpick comments (3)
web/src/composables/useLogs.ts (3)
1288-1288: Consider consistent error message handlingWhile the use of optional chaining is good, consider aligning this line with the previous error handling pattern for consistency:
- searchObj.data.errorMsg = err?.response?.data?.message || ""; + searchObj.data.errorMsg = err?.response?.data?.error || err?.response?.data?.message || "";This change would make the error handling more consistent throughout the function.
2310-2311: Implement centralized error handlingThe TODO comment suggests creating a
handleErrorfunction to centralize error handling logic. This is a good practice that can improve code maintainability and reduce duplication.Would you like assistance in implementing the
handleErrorfunction? I can provide a basic implementation that aligns with the current error handling patterns in the code.
Line range hint
2319-2350: Improved error handling with optional chainingThe changes in this segment significantly improve the error handling by using optional chaining and providing fallback values consistently. This makes the code more robust against undefined property access errors.
To further improve the code, consider reducing duplication by extracting the common error handling logic into a separate function. For example:
function extractErrorInfo(err: any) { const errorMsg = err?.response?.data?.error || err?.response?.data?.message || err?.message || "Unknown error"; const errorDetail = err?.response?.data?.error_detail || ""; const traceId = err?.response?.data?.trace_id || err?.trace_id || ""; return { errorMsg, errorDetail, traceId }; } // Usage const { errorMsg, errorDetail, traceId } = extractErrorInfo(err); searchObj.data.errorMsg = errorMsg; searchObj.data.errorDetail = errorDetail; // ... use traceId as neededThis refactoring would make the error handling more consistent and easier to maintain across different parts of the code.
🧰 Tools
🪛 ast-grep
[warning] 2316-2316: The application creates a database connection with an empty password. This can lead to unauthorized access by either an internal or external malicious actor. To prevent this vulnerability, enforce authentication when connecting to a database by using environment variables to securely provide credentials or retrieving them from a secure vault or HSM (Hardware Security Module).
Context: "Error while processing histogram request."
Note: [CWE-287] Improper Authentication. [REFERENCES]
- https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- web/src/composables/useLogs.ts (4 hunks)
- web/src/plugins/logs/Index.vue (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- web/src/plugins/logs/Index.vue
🧰 Additional context used
📓 Learnings (1)
web/src/composables/useLogs.ts (1)
Learnt from: omkarK06 PR: openobserve/openobserve#4842 File: web/src/composables/useLogs.ts:2332-2332 Timestamp: 2024-10-19T08:47:15.694Z Learning: Using `||` to provide default values when handling potentially undefined values, such as `err?.response?.data?.code || ""`, is acceptable and works correctly in `web/src/composables/useLogs.ts`.
🪛 ast-grep
web/src/composables/useLogs.ts
[warning] 2316-2316: The application creates a database connection with an empty password. This can lead to unauthorized access by either an internal or external malicious actor. To prevent this vulnerability, enforce authentication when connecting to a database by using environment variables to securely provide credentials or retrieving them from a secure vault or HSM (Hardware Security Module).
Context: "Error while processing histogram request."
Note: [CWE-287] Improper Authentication. [REFERENCES]
- https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
🔇 Additional comments (1)
web/src/composables/useLogs.ts (1)
1267-1270: Improved error handling with optional chainingThe changes in this segment enhance the error message construction by using optional chaining and providing multiple fallback options. This approach is more robust and prevents potential undefined property access errors.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor