1/*
2Copyright (c) 2015 VMware, Inc. All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package find
18
19import "fmt"
20
21type NotFoundError struct {
22	kind string
23	path string
24}
25
26func (e *NotFoundError) Error() string {
27	return fmt.Sprintf("%s '%s' not found", e.kind, e.path)
28}
29
30type MultipleFoundError struct {
31	kind string
32	path string
33}
34
35func (e *MultipleFoundError) Error() string {
36	return fmt.Sprintf("path '%s' resolves to multiple %ss", e.path, e.kind)
37}
38
39type DefaultNotFoundError struct {
40	kind string
41}
42
43func (e *DefaultNotFoundError) Error() string {
44	return fmt.Sprintf("no default %s found", e.kind)
45}
46
47type DefaultMultipleFoundError struct {
48	kind string
49}
50
51func (e DefaultMultipleFoundError) Error() string {
52	return fmt.Sprintf("default %s resolves to multiple instances, please specify", e.kind)
53}
54
55func toDefaultError(err error) error {
56	switch e := err.(type) {
57	case *NotFoundError:
58		return &DefaultNotFoundError{e.kind}
59	case *MultipleFoundError:
60		return &DefaultMultipleFoundError{e.kind}
61	default:
62		return err
63	}
64}
65