go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/rpc/errors.go (about)

     1  // Copyright 2022 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package rpc
    16  
    17  import (
    18  	"google.golang.org/grpc/codes"
    19  
    20  	"go.chromium.org/luci/grpc/appstatus"
    21  )
    22  
    23  // invalidArgumentError annotates err as having an invalid argument.
    24  // The error message is shared with the requester as is.
    25  //
    26  // Note that this differs from FailedPrecondition. It indicates arguments
    27  // that are problematic regardless of the state of the system
    28  // (e.g., a malformed file name).
    29  func invalidArgumentError(err error) error {
    30  	return appstatus.Attachf(err, codes.InvalidArgument, "%s", err)
    31  }
    32  
    33  // failedPreconditionError annotates err as failing a precondition for the
    34  // operation. The error message is shared with the requester as is.
    35  //
    36  // See codes.FailedPrecondition for more context about when this
    37  // should be used compared to invalid argument.
    38  func failedPreconditionError(err error) error {
    39  	return appstatus.Attachf(err, codes.FailedPrecondition, "%s", err)
    40  }