Publish identifier matches
[yangtools.git] / common / yang-common / src / main / java / org / opendaylight / yangtools / yang / common / RpcError.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.common;
9
10 import org.eclipse.jdt.annotation.NonNullByDefault;
11
12 /**
13  * Representation of an error.
14  */
15 public interface RpcError {
16     // FIXME: 8.0.0: remove this in favor of Netconf.ErrorSeverity
17     @NonNullByDefault
18     enum ErrorSeverity {
19         ERROR {
20             @Override
21             public org.opendaylight.yangtools.yang.common.ErrorSeverity toNetconf() {
22                 return org.opendaylight.yangtools.yang.common.ErrorSeverity.ERROR;
23             }
24         },
25         WARNING {
26             @Override
27             public org.opendaylight.yangtools.yang.common.ErrorSeverity toNetconf() {
28                 return org.opendaylight.yangtools.yang.common.ErrorSeverity.WARNING;
29             }
30         };
31
32         public abstract org.opendaylight.yangtools.yang.common.ErrorSeverity toNetconf();
33     }
34
35     /**
36      * Enumeration of {@code error-type} values. These provide glue between {@link NetconfLayer} and various sources of
37      * such errors.
38      */
39     // FIXME: 8.0.0: remove this in favor of common.ErrorType
40     @NonNullByDefault
41     enum ErrorType {
42         /**
43          * Indicates an error occurred during transport of data, eg over the network.
44          */
45         TRANSPORT {
46             @Override
47             public org.opendaylight.yangtools.yang.common.ErrorType toNetconf() {
48                 return org.opendaylight.yangtools.yang.common.ErrorType.TRANSPORT;
49             }
50         },
51         /**
52          * Indicates an error occurred during a remote procedure call.
53          */
54         RPC {
55             @Override
56             public org.opendaylight.yangtools.yang.common.ErrorType toNetconf() {
57                 return org.opendaylight.yangtools.yang.common.ErrorType.RPC;
58             }
59         },
60         /**
61          * Indicates an error at a protocol layer, eg if invalid data was passed by the caller.
62          */
63         PROTOCOL {
64             @Override
65             public org.opendaylight.yangtools.yang.common.ErrorType toNetconf() {
66                 return org.opendaylight.yangtools.yang.common.ErrorType.PROTOCOL;
67             }
68         },
69         /**
70          * Indicates an error occurred during internal processing.
71          */
72         APPLICATION {
73             @Override
74             public org.opendaylight.yangtools.yang.common.ErrorType toNetconf() {
75                 return org.opendaylight.yangtools.yang.common.ErrorType.APPLICATION;
76             }
77         };
78
79         public abstract org.opendaylight.yangtools.yang.common.ErrorType toNetconf();
80     }
81
82     /**
83      * Returns the error severity, as determined by the application reporting the error.
84      *
85      * @return an {@link ErrorSeverity} enum.
86      */
87     ErrorSeverity getSeverity();
88
89     /**
90      * Returns a short string that identifies the general type of error condition.
91      *
92      * <p>
93      * The following outlines suggested values as defined by
94      * (<a href="https://tools.ietf.org/html/rfc6241#page-89">RFC6241</a>):
95      *
96      * <pre>
97      *    access-denied
98      *    bad-attribute
99      *    bad-element
100      *    data-exists
101      *    data-missing
102      *    in-use
103      *    invalid-value
104      *    lock-denied
105      *    malformed-message
106      *    missing-attribute
107      *    missing-element
108      *    operation-failed
109      *    operation-not-supported
110      *    resource-denied
111      *    rollback-failed
112      *    too-big
113      *    unknown-attribute
114      *    unknown-element
115      *    unknown-namespace
116      * </pre>
117      * @return a string if available or null otherwise.
118      */
119     // FIXME: 8.0.0: return ErrorTag here
120     String getTag();
121
122     /**
123      * Returns a short string that identifies the specific type of error condition as
124      * determined by the application reporting the error.
125      *
126      * @return a string if available or null otherwise.
127      */
128     String getApplicationTag();
129
130     /**
131      * Returns a string suitable for human display that describes the error
132      * condition.
133      *
134      * @return a message string.
135      */
136     String getMessage();
137
138     /**
139      * Returns a string containing additional information to provide extended
140      * and/or implementation-specific debugging information.
141      *
142      * @return a string if available or null otherwise.
143      */
144     // FIXME: YANGTOOLS-765: this is wrong and needs to be modeled at data-api layer with YangErrorInfo
145     String getInfo();
146
147     /**
148      * Returns an exception cause.
149      *
150      * @return a Throwable if the error was triggered by exception, null otherwise.
151      */
152     Throwable getCause();
153
154     /**
155      * Returns the conceptual layer at which the error occurred.
156      *
157      * @return an {@link ErrorType} enum.
158      */
159     ErrorType getErrorType();
160 }