-
Notifications
You must be signed in to change notification settings - Fork 826
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 3087213
Showing
10 changed files
with
256 additions
and
67 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,52 @@ | ||
/* | ||
* 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 grpc | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
const ( | ||
remoteErrTpl = "[triggered by %s]" | ||
remoteErrSuffix = "[triggered by remote service]" | ||
handlerSideErrSuffix = "[triggered by handler side]" | ||
sendRSTStreamFrameSuffix = "[send RST Stream Frame]" | ||
) | ||
|
||
func remoteErrMsg(msg string) string { | ||
return msg + remoteErrSuffix | ||
} | ||
|
||
func remoteErrMsgf(msg string, a ...interface{}) string { | ||
return fmt.Sprintf(msg+remoteErrSuffix, a...) | ||
} | ||
|
||
func handlerSideErrMsg(msg string) string { | ||
return msg + handlerSideErrSuffix | ||
} | ||
|
||
func handlerSideErrMsgf(msg string, a ...interface{}) string { | ||
return fmt.Sprintf(msg+handlerSideErrSuffix, a...) | ||
} | ||
|
||
func sendRSTStreamFrameMsg(msg string) string { | ||
return msg + sendRSTStreamFrameSuffix | ||
} | ||
|
||
func sendRSTStreamFrameMsgf(msg string, a ...interface{}) string { | ||
return fmt.Sprintf(msg+sendRSTStreamFrameSuffix, a...) | ||
} |
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,16 @@ | ||
package grpc | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cloudwego/kitex/internal/test" | ||
) | ||
|
||
func TestErrMsg(t *testing.T) { | ||
test.Assert(t, remoteErrMsg("test") == "test[triggered by remote service]") | ||
test.Assert(t, remoteErrMsgf("test: %s", "val") == "test: val[triggered by remote service]") | ||
test.Assert(t, handlerSideErrMsg("test") == "test[triggered by handler side]") | ||
test.Assert(t, handlerSideErrMsgf("test: %s", "val") == "test: val[triggered by handler side]") | ||
test.Assert(t, sendRSTStreamFrameMsg("test") == "test[send RST Stream Frame]") | ||
test.Assert(t, sendRSTStreamFrameMsgf("test: %s", "val") == "test: val[send RST Stream Frame]") | ||
} |
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.