Skip to content

Commit 5c0aa32

Browse files
authored
Merge pull request #2178 from inteon/error_instead_of_panic
🌱Return an error if no httpClient is provided for `NewDynamicRESTMapper`
2 parents b9429e7 + a3d87b5 commit 5c0aa32

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

pkg/client/apiutil/dynamicrestmapper.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package apiutil
1818

1919
import (
20+
"fmt"
2021
"net/http"
2122
"sync"
2223
"sync/atomic"
@@ -78,7 +79,7 @@ func WithCustomMapper(newMapper func() (meta.RESTMapper, error)) DynamicRESTMapp
7879
// configure the RESTMapper.
7980
func NewDynamicRESTMapper(cfg *rest.Config, httpClient *http.Client, opts ...DynamicRESTMapperOption) (meta.RESTMapper, error) {
8081
if httpClient == nil {
81-
panic("httpClient must not be nil")
82+
return nil, fmt.Errorf("httpClient must not be nil, consider using rest.HTTPClientFor(c) to create a client")
8283
}
8384

8485
client, err := discovery.NewDiscoveryClientForConfigAndClient(cfg, httpClient)

0 commit comments

Comments
 (0)