refactor: improve exception logging for embedding utilities#765
Conversation
There was a problem hiding this comment.
Code Review
This pull request wraps model initialization and code embedding logic in try-except blocks to log exceptions before re-raising them. The reviewer points out that logging and re-raising in both functions results in duplicate stack traces, suggesting the removal of the redundant block in get_model(). Additionally, the reviewer recommends updating the log formatting in embed_code() to use brace-style formatting with loguru and removing a trailing comma.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Greptile SummaryThis PR improves logging around single-snippet embedding failures. The main changes are:
Confidence Score: 5/5Safe to merge with minimal risk. The code change is narrowly scoped to logging, keeps exception behavior unchanged, and follows the existing centralized log-message pattern. No files require special attention.
What T-Rex did
Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Caller
participant Embedder as embed_code
participant Cache as EmbeddingCache
participant Model as UniXcoder
participant Logger
Caller->>Embedder: embed_code(code, max_length)
Embedder->>Cache: get(code)
alt cache hit
Cache-->>Embedder: cached embedding
Embedder-->>Caller: embedding
else cache miss
Embedder->>Model: tokenize and infer embedding
Model-->>Embedder: sentence embedding
Embedder->>Cache: put(code, result)
Embedder-->>Caller: embedding
end
opt exception during embedding path
Embedder->>Logger: exception(EMBEDDING_SNIPPET_FAILED, length)
Embedder-->>Caller: re-raise original exception
end
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Caller
participant Embedder as embed_code
participant Cache as EmbeddingCache
participant Model as UniXcoder
participant Logger
Caller->>Embedder: embed_code(code, max_length)
Embedder->>Cache: get(code)
alt cache hit
Cache-->>Embedder: cached embedding
Embedder-->>Caller: embedding
else cache miss
Embedder->>Model: tokenize and infer embedding
Model-->>Embedder: sentence embedding
Embedder->>Cache: put(code, result)
Embedder-->>Caller: embedding
end
opt exception during embedding path
Embedder->>Logger: exception(EMBEDDING_SNIPPET_FAILED, length)
Embedder-->>Caller: re-raise original exception
end
|
|
@greptile review |
e376efe to
e380365
Compare
|
@greptile review |
|
Thanks @Shashank23123458867504 for the contribution! Merged with a small maintainer follow-up commit that moved the log literal into codebase_rag/logs.py and switched it to loguru's brace/kwargs formatting per repo convention. |
Summary
logger.exception()in embedding utilities.Type of Change
Related Issues
N/A
Test Plan
make test-paralleloruv run pytest -n auto -m "not integration")make test-integration, requires Docker)Manual Testing
logger.exception().Checklist
make pre-commit)# type: ignore,cast(),Any, orobjecttype hints