Skip to content

Conversation

@bogdanfazakas
Copy link
Member

@bogdanfazakas bogdanfazakas commented Jan 15, 2026

Fixes #1155 .

Changes proposed in this PR:

  • This PR adds defensive null/undefined checks around oceanNode.getDatabase() and its sub-stores (ddo, ddoState, logs, indexer) to prevent runtime crashes when the DB layer is not initialized / temporarily unavailable.
  • Instead of throwing (e.g. Cannot read properties of undefined), affected API handlers now fail gracefully with 503 Service Unavailable, while internal helpers log a warning and return undefined / default values where appropriate.

@bogdanfazakas
Copy link
Member Author

/run-security-scan

Copy link
Member

@alexcos20 alexcos20 left a comment

Choose a reason for hiding this comment

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

AI automated code review (Gemini 3).

Overall risk: low

Summary:
This pull request introduces comprehensive null and undefined checks for the database instance and its specific sub-components (like ddo, ddoState, logs, indexer) across various handlers and utility functions. This change significantly improves the robustness of the application by preventing runtime errors that could occur if a database component is unexpectedly unavailable. Error handling for database unavailability is implemented by returning 503 Service Unavailable for API endpoints and logging warnings or returning undefined for internal utility functions.

Comments:
• [INFO][style] The pattern if (!database || !database.ddo) (and similar for other database properties) is repeated across multiple files. While functionally correct, consider if using optional chaining like if (!database?.ddo) could improve conciseness and readability, assuming database could be null/undefined. This would align with modern TypeScript/JavaScript practices.
• [WARNING][other] The use of CORE_LOGGER.logMessage(..., true) here is less explicit about the intended log level compared to CORE_LOGGER.error or CORE_LOGGER.log(LOG_LEVELS_STR.LEVEL_WARN, ...). For consistency and clarity in logging, it would be better to use a specific log level function (e.g., CORE_LOGGER.warn or CORE_LOGGER.info) if available, or CORE_LOGGER.log(LOG_LEVELS_STR.LEVEL_INFO, ...).

@bogdanfazakas bogdanfazakas marked this pull request as ready for review January 20, 2026 09:33
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.

TypeError when database is not fully initialized

4 participants