Add YangError interface 38/85738/6
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 9 Nov 2019 04:28:32 +0000 (05:28 +0100)
committerRobert Varga <nite@hq.sk>
Thu, 9 Apr 2020 14:25:04 +0000 (14:25 +0000)
This adds the interface for communicating details about a failure
triggered by a YANG-defined constraint.

JIRA: YANGTOOLS-176
Change-Id: I9139c086668742005490bd52d55fdb26e7ef70b9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
Signed-off-by: Tadei Bilan <tadei.bilan@pantheon.tech>
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/YangError.java [new file with mode: 0644]

diff --git a/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/YangError.java b/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/YangError.java
new file mode 100644 (file)
index 0000000..3c01af2
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.common;
+
+import com.google.common.annotations.Beta;
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
+
+/**
+ * An error condition raised as a consequence of a YANG-defined contract. This interface should not be directly
+ * implemented, but rather should be attached to a well-defined Exception class.
+ *
+ * @author Robert Varga
+ */
+@Beta
+public interface YangError {
+    /**
+     * Returns the conceptual layer at which the error occurred.
+     *
+     * @return an {@link ErrorType} enum.
+     */
+    @NonNull ErrorType getErrorType();
+
+    /**
+     * Returns the error severity, as determined by the application reporting the error.
+     *
+     * @return an {@link ErrorSeverity} enum.
+     */
+    @NonNull ErrorSeverity getSeverity();
+
+    /**
+     * Returns the value of the argument of YANG <code>error-app-tag</code> keyword.
+     *
+     * @return string with the application tag, or empty if it was not provided.
+     */
+    Optional<String> getErrorAppTag();
+
+    /**
+     * Returns the value of the argument of YANG <code>error-message</code> keyword.
+     *
+     * @return string with the error message, or empty if it was not provided.
+     */
+    Optional<String> getErrorMessage();
+}