fix: prevent nil pointer panic when importing social providers#140
fix: prevent nil pointer panic when importing social providers#140
Conversation
Add nil checks to all console API client methods (GetProject, PatchProject, CreateProject, DeleteProject, workspace/event stream/API key operations) that could panic when called without a workspace API key configured. Previously, calling these methods with only a project API key would cause a nil pointer dereference on the uninitialized consoleClient field. Now they return a descriptive error message guiding the user to set ORY_WORKSPACE_API_KEY. Fixes #137
There was a problem hiding this comment.
Pull request overview
Fixes a nil pointer dereference when console API methods are invoked without a configured workspace API key by adding a shared guard (requireConsoleClient) and validating behavior via unit tests.
Changes:
- Added
requireConsoleClient()to centralize the “console client not configured” check and error message. - Added the guard to multiple console API methods (projects, workspaces, API keys, event streams, orgs) to prevent panics.
- Added a unit test ensuring several console API methods return a descriptive error when
consoleClientis nil.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| internal/client/client.go | Introduces requireConsoleClient and applies it across console API methods to prevent nil dereferences. |
| internal/client/client_test.go | Adds a regression test to ensure missing workspace API key yields a descriptive error instead of panicking. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
- Rename test to TestOryClient_RequireConsoleClient_NilReturnsError - Add sentinel error ErrConsoleClientNotConfigured for errors.Is checks - Add subtests for all guarded methods: UpdateWorkspace, CreateProjectAPIKey, ListProjectAPIKeys, DeleteProjectAPIKey, CreateEventStream, GetEventStream, SetEventStream, DeleteEventStream, ListEventStreams
There was a problem hiding this comment.
Pull request overview
Fixes a nil pointer dereference when console API methods are called without a configured workspace API key by introducing a shared guard and adding unit coverage to ensure methods return a descriptive error instead of panicking.
Changes:
- Added
ErrConsoleClientNotConfiguredandrequireConsoleClient()to guard console API calls whenconsoleClientis nil - Added
requireConsoleClient()checks to multiple console API methods (projects, workspaces, API keys, event streams, organizations) - Added a unit test that exercises the affected console API methods when
WorkspaceAPIKeyis absent
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| internal/client/client.go | Adds a sentinel error + helper guard and uses it to prevent nil consoleClient panics across console API methods |
| internal/client/client_test.go | Adds a regression test ensuring console API methods return the sentinel error when consoleClient is uninitialized |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
Fixes a nil pointer dereference panic that crashes the provider when importing social providers (or calling any console API operation) without a workspace API key configured.
The root cause was that
OryClient.consoleClientis only initialized whenworkspace_api_keyis set, but several console API methods (GetProject, PatchProject, CreateProject, DeleteProject, and workspace/event stream/API key operations) accessed it without checking for nil first.Related Issues
Fixes #137
Type of Change
Checklist
make test)make format)Testing
Unit tests added
TestOryClient_RequireConsoleClient_NilPanics- Verifies that all console API methods (GetProject, PatchProject, CreateProject, DeleteProject, CreateWorkspace, GetWorkspace, ListWorkspaces, ListOrganizations) return a descriptive error instead of panicking whenconsoleClientis nil.What changed
requireConsoleClient()helper method onOryClientthat returns a clear error if the console API client is not initializedGetProject,CreateProject,DeleteProject,PatchProjectCreateWorkspace,GetWorkspace,UpdateWorkspace,ListWorkspacesCreateProjectAPIKey,ListProjectAPIKeys,DeleteProjectAPIKeyCreateEventStream,GetEventStream,SetEventStream,DeleteEventStream,ListEventStreamsListOrganizationsScreenshots/Output
Before (panic):
After (descriptive error):