-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
240f4ab
commit 963f2d1
Showing
20 changed files
with
993 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2024 CloudWeGo Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package kerrors | ||
|
||
var ( | ||
// ErrStreamingProtocol is the parent type of all streaming protocol(e.g. gRPC, TTHeader Streaming) | ||
// related but not user-aware errors. | ||
ErrStreamingProtocol = &basicError{"streaming protocol error"} | ||
ErrStreamTimeout = &basicError{"stream timeout"} | ||
ErrBizCanceled = &basicError{"business canceled"} | ||
ErrNonBizCanceled = &basicError{"non-business canceled"} | ||
ErrMetaSizeExceeded = &basicError{"meta size exceeds limit"} | ||
ErrMetaContentIllegal = &basicError{"meta content illegal"} | ||
ErrGracefulShutdown = &basicError{"graceful shutdown"} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* | ||
* Copyright 2024 gRPC authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* This file may have been modified by CloudWeGo authors. All CloudWeGo | ||
* Modifications are Copyright 2021 CloudWeGo Authors. | ||
*/ | ||
|
||
package errors | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/cloudwego/kitex/pkg/kerrors" | ||
) | ||
|
||
// This package contains all the errors suitable for Kitex errors model. | ||
// These errors should not be used by user directly. | ||
// If users need to perceive these errors, the pkg/streamx/provider/grpc/gerrors package should be used. | ||
var ( | ||
// stream error | ||
ErrHTTP2Stream = newErrType("HTTP2Stream err") | ||
ErrClosedWithoutTrailer = newErrType("client received Data frame with END_STREAM flag") | ||
ErrMiddleHeader = newErrType("Headers frame appeared in the middle of a stream") | ||
ErrDecodeHeader = newErrType("decoded Headers frame failed") | ||
ErrRecvRstStream = newErrType("received RstStream frame") | ||
ErrStreamDrain = newErrType("stream rejected by draining connection") | ||
ErrStreamFlowControl = newErrType("stream-level flow control") | ||
ErrIllegalHeaderWrite = newErrType("Illegal header write") | ||
|
||
// connection error | ||
ErrHTTP2Connection = newErrType("HTTP2Connection err") | ||
ErrEstablishConnection = newErrType("established connection failed") | ||
ErrHandleGoAway = newErrType("handled GoAway Frame failed") | ||
ErrKeepAlive = newErrType("keepalive failed") | ||
ErrOperateHeaders = newErrType("operated Headers Frame failed") | ||
ErrNoActiveStream = newErrType("no active stream") | ||
) | ||
|
||
type errType struct { | ||
message string | ||
// parent errType | ||
basic error | ||
} | ||
|
||
func newErrType(message string) *errType { | ||
return &errType{message: message, basic: kerrors.ErrStreamingProtocol} | ||
} | ||
|
||
func (e *errType) Error() string { | ||
if e.basic == nil { | ||
return e.message | ||
} | ||
return fmt.Sprintf("%s - %s", e.basic.Error(), e.message) | ||
} | ||
|
||
func (e *errType) Is(target error) bool { | ||
return target == e || errors.Is(e.basic, target) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* | ||
* Copyright 2024 gRPC authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* This file may have been modified by CloudWeGo authors. All CloudWeGo | ||
* Modifications are Copyright 2021 CloudWeGo Authors. | ||
*/ | ||
|
||
package errors | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/cloudwego/kitex/internal/test" | ||
"github.com/cloudwego/kitex/pkg/kerrors" | ||
) | ||
|
||
var errs = []*errType{ | ||
// stream error | ||
ErrHTTP2Stream, | ||
ErrClosedWithoutTrailer, | ||
ErrMiddleHeader, | ||
ErrDecodeHeader, | ||
ErrRecvRstStream, | ||
ErrStreamDrain, | ||
ErrStreamFlowControl, | ||
ErrIllegalHeaderWrite, | ||
// connection error | ||
ErrHTTP2Connection, | ||
ErrEstablishConnection, | ||
ErrHandleGoAway, | ||
ErrKeepAlive, | ||
ErrOperateHeaders, | ||
ErrNoActiveStream, | ||
} | ||
|
||
func TestErrType(t *testing.T) { | ||
for _, err := range errs { | ||
test.Assert(t, errors.Is(err, kerrors.ErrStreamingProtocol), err) | ||
test.Assert(t, kerrors.IsKitexError(err), err) | ||
test.Assert(t, strings.Contains(err.Error(), err.message), err) | ||
test.Assert(t, strings.Contains(err.Error(), err.basic.Error()), err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.