Skip to content

Commit

Permalink
replace grpc code to connect-rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
hugehoo committed Feb 22, 2025
1 parent 5299469 commit 4cadaf9
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions cmd/yorkie/project/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"errors"
"fmt"

"connectrpc.com/connect"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"google.golang.org/genproto/googleapis/rpc/errdetails"
"google.golang.org/grpc/status"
"gopkg.in/yaml.v3"

"github.com/yorkie-team/yorkie/admin"
Expand Down Expand Up @@ -61,13 +61,21 @@ func newCreateCommand() *cobra.Command {
ctx := context.Background()
project, err := cli.CreateProject(ctx, name)
if err != nil {
// TODO(chacha912): consider creating the error details type to remove the dependency on gRPC.
st := status.Convert(err)
for _, detail := range st.Details() {
switch t := detail.(type) {
case *errdetails.BadRequest:
for _, violation := range t.GetFieldViolations() {
cmd.Printf("Invalid Fields: The %q field was wrong: %s\n", violation.GetField(), violation.GetDescription())
var connErr *connect.Error
if errors.As(err, &connErr) {
for _, detail := range connErr.Details() {
value, err := detail.Value()
if err != nil {
continue
}

badReq, ok := value.(*errdetails.BadRequest)
if !ok {
continue
}

for _, violation := range badReq.GetFieldViolations() {
cmd.Printf("Invalid Field: %q - %s\n", violation.GetField(), violation.GetDescription())
}
}
}
Expand Down

0 comments on commit 4cadaf9

Please sign in to comment.