fix: improve robustness with nil-safe context handling and proper error propagation#664
fix: improve robustness with nil-safe context handling and proper error propagation#664Rayhan1967 wants to merge 12 commits intolaunchdarkly:mainfrom
Conversation
- Fix invalid on-failure block in check-openapi-updates.yml workflow - Add --host flag to dev-server (default 127.0.0.1, use 0.0.0.0 for external connections) - Update test golden file to include new host flag
… improvements - Add nil check in StoreFromContext to prevent panic - Handle HTTP request error properly in resources client - Implement SDK client caching to avoid creating new clients per request - Pin Go version to 1.23 in CI workflow - Add security documentation for pull_request_target workflow
| SLACK_TITLE: ':warning: The OpenAPI spec has changed and resources need to be updated.' | ||
| SLACK_USERNAME: github | ||
| SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
| continue-on-error: true |
There was a problem hiding this comment.
Slack failure notification silently removed and replaced with no-op
Medium Severity
The on-failure job that sent Slack notifications when the OpenAPI spec check failed has been completely removed and replaced with continue-on-error: true at the job level. This silently swallows failures instead of alerting the team, meaning the team will no longer be notified when the OpenAPI spec changes and resources need updating.
…cern - Add cleanup goroutine that runs every minute - Idle clients (no refs, unused for 5 minutes) are automatically closed - Add Close() method to Sdk interface for graceful shutdown - Update mock to implement the new Close() method
- Simplified SDK client caching without background cleanup goroutines - Cached clients stored per streamingSdk instance (request-scoped) - Added Close() method for graceful cleanup on server shutdown - Made GetSdk nil-safe to match StoreFromContext fix This reduces the concurrency complexity while maintaining the performance benefit of SDK client reuse within a server instance lifecycle.
- Add GetOutputKind function from main branch - Keep HostFlag and HostFlagDescription from fix branch - Add JSONFlag and JSONFlagDescription from main branch - Ensure all constants are properly exported
… leak Revert to original approach with proper defer Close() to: - Fix race condition where concurrent requests could create multiple clients - Ensure SDK clients are properly closed after each request - Maintain interface compatibility with Close() method (returns nil) The original caching approach had check-then-create-then-set race condition that could leak clients and was ineffective since newSdk() is called per request.
| return "json" | ||
| } | ||
| return viper.GetString(OutputFlag) | ||
| } |
There was a problem hiding this comment.
New exported function GetOutputKind is never called
Low Severity
The newly added exported function GetOutputKind is not called anywhere in the codebase. Additionally, the JSONFlag constant it references ("json") is never registered as a persistent boolean flag on any command, so cmd.Root().PersistentFlags().GetBool(JSONFlag) would always return an error, making the "json" branch unreachable even if the function were called.


Summary
This PR improves the robustness of the LaunchDarkly CLI by addressing critical error handling gaps and enhancing CI/CD configuration stability.
Changes
Bug Fixes
internal/dev_server/model/store.goStoreFromContextwould panic if the store was not found in contextinternal/resources/client.gohttp.NewRequesterrors were silently ignoredinternal/dev_server/adapters/sdk.goGetSdkfunction andClose()method to interfaceCI/CD Improvements
.github/workflows/go.yml1.23(explicit) instead ofstableubuntu-24.04setup-goto@v5.github/workflows/lint-pr-title.ymlpermissions: contents: readfor least-privilege securitypull_request_targetusageTesting
✅ All existing tests pass
✅ Build succeeds
✅ No breaking changes to public APIs
Checklist