Skip to content

Commit fc423fc

Browse files
authored
Merge pull request #2164 from inteon/error_instead_of_panic
🌱Return an error if no httpClient is provided
2 parents 9361b25 + cbe07b6 commit fc423fc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pkg/client/apiutil/apimachinery.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func AddToProtobufScheme(addToScheme func(*runtime.Scheme) error) error {
6464
// information fetched by a new client with the given config.
6565
func NewDiscoveryRESTMapper(c *rest.Config, httpClient *http.Client) (meta.RESTMapper, error) {
6666
if httpClient == nil {
67-
panic("httpClient must not be nil")
67+
return nil, fmt.Errorf("httpClient must not be nil, consider using rest.HTTPClientFor(c) to create a client")
6868
}
6969

7070
// Get a mapper
@@ -157,7 +157,7 @@ func GVKForObject(obj runtime.Object, scheme *runtime.Scheme) (schema.GroupVersi
157157
// baseConfig, if set, otherwise a default serializer will be set.
158158
func RESTClientForGVK(gvk schema.GroupVersionKind, isUnstructured bool, baseConfig *rest.Config, codecs serializer.CodecFactory, httpClient *http.Client) (rest.Interface, error) {
159159
if httpClient == nil {
160-
panic("httpClient must not be nil")
160+
return nil, fmt.Errorf("httpClient must not be nil, consider using rest.HTTPClientFor(c) to create a client")
161161
}
162162
return rest.RESTClientForConfigAndClient(createRestConfig(gvk, isUnstructured, baseConfig, codecs), httpClient)
163163
}

0 commit comments

Comments
 (0)