You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2022/04/14 11:27:19 UTC

[GitHub] [skywalking-banyandb] lujiajing1126 commented on a diff in pull request #100: Return error created from status

lujiajing1126 commented on code in PR #100:
URL: https://github.com/apache/skywalking-banyandb/pull/100#discussion_r850349468


##########
banyand/metadata/schema/error.go:
##########
@@ -0,0 +1,59 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you 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 schema
+
+import (
+	"fmt"
+
+	"github.com/pkg/errors"
+	"google.golang.org/genproto/googleapis/rpc/errdetails"
+	"google.golang.org/grpc/codes"
+	"google.golang.org/grpc/status"
+)
+
+var (
+	statusGRPCInvalidArgument  = status.New(codes.InvalidArgument, "banyandb: input is invalid")
+	ErrGRPCInvalidArgument     = statusGRPCInvalidArgument.Err()
+	statusGRPCResourceNotFound = status.New(codes.NotFound, "banyandb: resource not found")
+	ErrGRPCResourceNotFound    = statusGRPCResourceNotFound.Err()
+	statusGRPCAlreadyExists    = status.New(codes.AlreadyExists, "banyandb: resource already exists")
+	ErrGRPCAlreadyExists       = statusGRPCAlreadyExists.Err()
+)
+
+func IsNotFound(err error) bool {
+	return errors.Is(err, ErrGRPCResourceNotFound)
+}
+
+// BadRequest creates a gRPC error with error details with type BadRequest,
+// which describes violations in a client request.
+func BadRequest(field, desc string) error {
+	v := &errdetails.BadRequest_FieldViolation{
+		Field:       field,
+		Description: desc,
+	}
+	br := &errdetails.BadRequest{}
+	br.FieldViolations = append(br.FieldViolations, v)
+	st, err := statusGRPCInvalidArgument.WithDetails(br)
+	if err != nil {

Review Comment:
   > @lujiajing1126 AFAIK, you don't have to handle this error.
   
   Fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org