fix: prevent panic when artifact service is not configured#601
fix: prevent panic when artifact service is not configured#601IsAmos01 wants to merge 1 commit intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @IsAmos01, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue where the application would crash with a nil pointer dereference if the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a panic that occurs when the artifact service is not configured by adding nil checks. The changes are well-tested with both unit and integration tests. I have a couple of suggestions to improve code maintainability and consistency by reducing code duplication.
| if ia.Artifacts == nil { | ||
| return nil, fmt.Errorf("artifact service is not configured: please configure ArtifactService in the runner") | ||
| } |
There was a problem hiding this comment.
The error message string "artifact service is not configured: please configure ArtifactService in the runner" is duplicated in this function and also in List, Load, and LoadVersion. To improve maintainability and avoid potential inconsistencies, please extract it into a package-level constant.
For example:
const artifactServiceNotConfiguredMsg = "artifact service is not configured: please configure ArtifactService in the runner"Then you can use fmt.Errorf(artifactServiceNotConfiguredMsg) here and in the other methods.
|
@google-cla-bot check |
1 similar comment
|
@google-cla-bot check |
2ea38b6 to
683fc6c
Compare
|
@google-cla-bot check |
683fc6c to
aab2046
Compare
|
@google-cla-bot check |
1 similar comment
|
@google-cla-bot check |
Fixes google#283 ## Problem When using loadartifactstool without properly configuring an ArtifactService in the runner, the application crashes with a nil pointer dereference panic instead of returning a helpful error message. ## Solution Added nil checks in the internalArtifacts wrapper methods (List, Load, LoadVersion, and Save) to return a descriptive error when the artifact service is not configured. ## Changes - Added nil checks using artifactServiceNotConfiguredMsg constant - Replaced custom contains() helper with strings.Contains() from stdlib - Added comprehensive unit tests to verify error handling when artifact service is nil - Added integration test in loadartifactstool to ensure graceful error handling ## Testing Plan - Unit tests in internal/toolinternal/context_test.go verify that all artifact methods return proper errors when service is nil - Integration test in load_artifacts_tool_test.go verifies that ProcessRequest returns error instead of panicking - All existing tests continue to pass Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
aab2046 to
b5db7f2
Compare
|
@google-cla-bot check |
Fix: Prevent Panic When Artifact Service Is Not Configured
Fixes #283
🐛 Problem
When using
loadartifactstoolwithout properly configuring anArtifactServicein the runner, the application crashes with a nil pointer dereference panic:This provides a poor developer experience as the error is not caught early and the crash message doesn't clearly explain the misconfiguration.
✅ Solution
Added nil checks in the
internalArtifactswrapper methods to return a descriptive error when the artifact service is not configured.Changes Made
Added nil checks in
internal/toolinternal/context.go:List()- checks for nil before calling underlying serviceLoad()- checks for nil before calling underlying serviceLoadVersion()- checks for nil before calling underlying serviceSave()- checks for nil before calling underlying serviceClear error message:
Comprehensive test coverage:
internal/toolinternal/context_test.goverify error handling for all methodstool/loadartifactstool/load_artifacts_tool_test.goensures graceful error handling🧪 Testing Plan
Unit Tests
TestInternalArtifacts_NilArtifactsService- Tests all four methods (List, Load, LoadVersion, Save) return proper errors when service is nilIntegration Test
TestLoadArtifactsTool_ProcessRequest_NilArtifactService- EnsuresProcessRequestreturns error instead of panicking when artifact service is not configuredRegression Testing
📝 Testing Evidence
🔍 Code Review Notes
SearchMemory()(line 104-106 in context.go)📚 Related