Blame vendor/github.com/Azure/go-autorest/autorest/validation/error.go

Packit Service 4d2de5
package validation
Packit Service 4d2de5
Packit Service 4d2de5
// Copyright 2017 Microsoft Corporation
Packit Service 4d2de5
//
Packit Service 4d2de5
//  Licensed under the Apache License, Version 2.0 (the "License");
Packit Service 4d2de5
//  you may not use this file except in compliance with the License.
Packit Service 4d2de5
//  You may obtain a copy of the License at
Packit Service 4d2de5
//
Packit Service 4d2de5
//      http://www.apache.org/licenses/LICENSE-2.0
Packit Service 4d2de5
//
Packit Service 4d2de5
//  Unless required by applicable law or agreed to in writing, software
Packit Service 4d2de5
//  distributed under the License is distributed on an "AS IS" BASIS,
Packit Service 4d2de5
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit Service 4d2de5
//  See the License for the specific language governing permissions and
Packit Service 4d2de5
//  limitations under the License.
Packit Service 4d2de5
Packit Service 4d2de5
import (
Packit Service 4d2de5
	"fmt"
Packit Service 4d2de5
)
Packit Service 4d2de5
Packit Service 4d2de5
// Error is the type that's returned when the validation of an APIs arguments constraints fails.
Packit Service 4d2de5
type Error struct {
Packit Service 4d2de5
	// PackageType is the package type of the object emitting the error. For types, the value
Packit Service 4d2de5
	// matches that produced the the '%T' format specifier of the fmt package. For other elements,
Packit Service 4d2de5
	// such as functions, it is just the package name (e.g., "autorest").
Packit Service 4d2de5
	PackageType string
Packit Service 4d2de5
Packit Service 4d2de5
	// Method is the name of the method raising the error.
Packit Service 4d2de5
	Method string
Packit Service 4d2de5
Packit Service 4d2de5
	// Message is the error message.
Packit Service 4d2de5
	Message string
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// Error returns a string containing the details of the validation failure.
Packit Service 4d2de5
func (e Error) Error() string {
Packit Service 4d2de5
	return fmt.Sprintf("%s#%s: Invalid input: %s", e.PackageType, e.Method, e.Message)
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// NewError creates a new Error object with the specified parameters.
Packit Service 4d2de5
// message is treated as a format string to which the optional args apply.
Packit Service 4d2de5
func NewError(packageType string, method string, message string, args ...interface{}) Error {
Packit Service 4d2de5
	return Error{
Packit Service 4d2de5
		PackageType: packageType,
Packit Service 4d2de5
		Method:      method,
Packit Service 4d2de5
		Message:     fmt.Sprintf(message, args...),
Packit Service 4d2de5
	}
Packit Service 4d2de5
}