mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-16 14:45:28 +00:00
Replace code that eats errors with a more consistent reporting
In order to allow certain programmer error / unexpected error states to be captured, replace sections that log and eat errors with a method that can be centrally replaced. This captures two common error sources, replication errors, and apiserver code that returns invalid errors.
This commit is contained in:
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/healthz"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
|
||||
|
||||
"github.com/emicklei/go-restful"
|
||||
@@ -373,6 +374,7 @@ func errorJSON(err error, codec runtime.Codec, w http.ResponseWriter) {
|
||||
|
||||
// errorJSONFatal renders an error to the response, and if codec fails will render plaintext
|
||||
func errorJSONFatal(err error, codec runtime.Codec, w http.ResponseWriter) {
|
||||
util.HandleError(fmt.Errorf("apiserver was unable to write a JSON response: %v", err))
|
||||
status := errToAPIStatus(err)
|
||||
output, err := codec.Encode(status)
|
||||
if err != nil {
|
||||
@@ -387,7 +389,6 @@ func errorJSONFatal(err error, codec runtime.Codec, w http.ResponseWriter) {
|
||||
|
||||
// writeRawJSON writes a non-API object in JSON.
|
||||
func writeRawJSON(statusCode int, object interface{}, w http.ResponseWriter) {
|
||||
// PR #2243: Pretty-print JSON by default.
|
||||
output, err := json.MarshalIndent(object, "", " ")
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
@@ -22,7 +22,7 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
||||
"github.com/golang/glog"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
// statusError is an object that can be converted into an api.Status
|
||||
@@ -49,7 +49,7 @@ func errToAPIStatus(err error) *api.Status {
|
||||
// by REST storage - these typically indicate programmer
|
||||
// error by not using pkg/api/errors, or unexpected failure
|
||||
// cases.
|
||||
glog.V(1).Infof("An unchecked error was received: %v", err)
|
||||
util.HandleError(fmt.Errorf("apiserver received an error that is not an api.Status: %v", err))
|
||||
return &api.Status{
|
||||
Status: api.StatusFailure,
|
||||
Code: status,
|
||||
|
Reference in New Issue
Block a user