Skip to content

feat: improve startup and save/read failure logging#47

Open
anshuman9468 wants to merge 1 commit intodbpedia:masterfrom
anshuman9468:fix/logging-improvement
Open

feat: improve startup and save/read failure logging#47
anshuman9468 wants to merge 1 commit intodbpedia:masterfrom
anshuman9468:fix/logging-improvement

Conversation

@anshuman9468
Copy link

@anshuman9468 anshuman9468 commented Mar 17, 2026

Overview

This PR adds SLF4J logging to improve observability during startup and Git operations, making debugging faster and clearer.

Changes

  • Startup Logs: Indicates whether LocalGitClient or RemoteGitlabHttpClient is used.
  • Config Validation: getRequiredParam logs and throws errors for missing required configs.
  • Error Handling: Logs failures in graph store read/write operations.
  • Git Logging:
    • Local: Logs repo path on initialization
    • Remote: Logs OAuth flow and GitLab project/auth errors

Context

Fixes unclear failures caused by misconfiguration, invalid GitLab credentials, or Git operation issues.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved configuration parameter validation with stricter enforcement and clearer error messages.
  • Chores

    • Enhanced logging throughout core API and Git operations to improve diagnostics and troubleshooting capabilities.

@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

📝 Walkthrough

Walkthrough

The changes augment two Scala files with comprehensive logging support via SLF4J and improve error handling. ApiImpl.scala introduces stricter parameter validation with a helper function and wraps operations with error recovery. GitClient.scala adds logging around Git operations and token retrieval.

Changes

Cohort / File(s) Summary
API Implementation Logging & Validation
src/main/scala/org/dbpedia/databus/ApiImpl.scala
Adds SLF4J logging throughout initialization and file operations. Introduces getRequiredParam helper to enforce required configuration parameters with descriptive errors. Wraps file operations and Git interactions with recoverWith for error logging and re-throw semantics.
Git Client Logging
src/main/scala/org/dbpedia/databus/GitClient.scala
Adds SLF4J logging to LocalGitClient and RemoteGitlabHttpClient. Logs repository paths, token retrieval attempts/failures, and project lookup failures while maintaining existing error semantics.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main changes: adding logging for startup processes and file read/write failure scenarios, which aligns with the substantial logging additions throughout ApiImpl and GitClient.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use OpenGrep to find security vulnerabilities and bugs across 17+ programming languages.

OpenGrep is compatible with Semgrep configurations. Add an opengrep.yml or semgrep.yml configuration file to your project to enable OpenGrep analysis.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/main/scala/org/dbpedia/databus/GitClient.scala (1)

154-168: Consider sanitizing error message before logging.

The error message e comes directly from the GitLab API response body, which could potentially contain sensitive information (tokens, credentials, or internal server details). Consider logging a generic failure message or sanitizing the response before logging.

🛡️ Suggested approach
       case Left(e) =>
-        log.error(s"Failed to get access token from Gitlab: $e")
+        log.error("Failed to get access token from Gitlab")
+        log.debug(s"Token retrieval error details: $e")
         Failure(new RuntimeException(e))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/scala/org/dbpedia/databus/GitClient.scala` around lines 154 - 168,
The accessToken block is logging the raw GitLab response body (variable e) which
may contain sensitive data; update the error handling in the Try within
accessToken (around authReq(rootUser, rootPass) and backend.send(req).body) to
avoid logging the full response: log a generic error message (e.g., "Failed to
get access token from GitLab") and if you need details log a sanitized/truncated
version at debug level or attach a non-sensitive status, and change the Failure
to include a non-sensitive message (e.g., new RuntimeException("Failed to
retrieve access token")) while preserving original response only in a debug or
internal variable after sanitization.
src/main/scala/org/dbpedia/databus/ApiImpl.scala (1)

250-256: Consider moving logger to companion object scope.

LoggerFactory.getLogger(ApiImpl.getClass) is called each time getRequiredParam is invoked, which creates a logger lookup on each call. While SLF4J typically caches loggers internally, it's more idiomatic to define the logger once at the object level.

♻️ Suggested improvement

Add a logger at the Config object level:

object Config {
  private val log = LoggerFactory.getLogger(ApiImpl.getClass)
  // ...
}

Then use it in getRequiredParam:

       def getRequiredParam(name: String): String = {
         getParam(name).getOrElse({
           val msg = s"Missing required configuration parameter: $name"
-          LoggerFactory.getLogger(ApiImpl.getClass).error(msg)
+          log.error(msg)
           throw new NoSuchElementException(msg)
         })
       }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/scala/org/dbpedia/databus/ApiImpl.scala` around lines 250 - 256,
Move the logger instantiation out of getRequiredParam to the companion/object
scope so it is created once: add a private val (e.g. log) in the Config /
ApiImpl companion object using LoggerFactory.getLogger(ApiImpl.getClass) and
then replace the inline LoggerFactory.getLogger(...) call inside
getRequiredParam with that private log variable; update any references
accordingly so getRequiredParam uses the shared logger instance instead of
creating a new one on each call.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/main/scala/org/dbpedia/databus/ApiImpl.scala`:
- Around line 250-256: Move the logger instantiation out of getRequiredParam to
the companion/object scope so it is created once: add a private val (e.g. log)
in the Config / ApiImpl companion object using
LoggerFactory.getLogger(ApiImpl.getClass) and then replace the inline
LoggerFactory.getLogger(...) call inside getRequiredParam with that private log
variable; update any references accordingly so getRequiredParam uses the shared
logger instance instead of creating a new one on each call.

In `@src/main/scala/org/dbpedia/databus/GitClient.scala`:
- Around line 154-168: The accessToken block is logging the raw GitLab response
body (variable e) which may contain sensitive data; update the error handling in
the Try within accessToken (around authReq(rootUser, rootPass) and
backend.send(req).body) to avoid logging the full response: log a generic error
message (e.g., "Failed to get access token from GitLab") and if you need details
log a sanitized/truncated version at debug level or attach a non-sensitive
status, and change the Failure to include a non-sensitive message (e.g., new
RuntimeException("Failed to retrieve access token")) while preserving original
response only in a debug or internal variable after sanitization.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 942289a9-c1b0-4af8-9596-daba5b01e2a1

📥 Commits

Reviewing files that changed from the base of the PR and between 246178f and fedbe34.

📒 Files selected for processing (2)
  • src/main/scala/org/dbpedia/databus/ApiImpl.scala
  • src/main/scala/org/dbpedia/databus/GitClient.scala

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.

2 participants