2 * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.data.api.codec;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import java.util.Optional;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
17 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
18 import org.opendaylight.yangtools.yang.common.YangError;
19 import org.opendaylight.yangtools.yang.model.api.ConstraintMetaDefinition;
22 * Dedicated exception for reporting conditions where {@code error-tag} should be reported as {@code invalid-value}.
23 * This is covered by <a href="https://tools.ietf.org/html/rfc7950#section-8.3.1">RFC7950 section 8.3.1</a>:
25 * If a leaf data value does not match the type constraints for the
26 * leaf, including those defined in the type's "range", "length", and
27 * "pattern" properties, the server MUST reply with an
28 * "invalid-value" <error-tag> in the <rpc-error>, and with the
29 * error-app-tag (Section 7.5.4.2) and error-message
30 * (Section 7.5.4.1) associated with the constraint, if any exist.
34 * This error tag also references <a href="https://tools.ietf.org/html/rfc6241#appendix-A">RFC6241 Appendix A</a>,
35 * which defines the appropriate severity and adds more semantics.
38 public class YangInvalidValueException extends IllegalArgumentException implements YangError {
39 private static final long serialVersionUID = 1L;
41 private final @NonNull ErrorType errorType;
42 private final @Nullable String errorAppTag;
43 private final @Nullable String errorMessage;
45 public YangInvalidValueException(final ErrorType errorType, final ConstraintMetaDefinition constraint,
46 final String message) {
47 super(requireNonNull(message));
48 this.errorType = requireNonNull(errorType);
49 this.errorAppTag = constraint.getErrorAppTag().orElse(null);
50 this.errorMessage = constraint.getErrorMessage().orElse(null);
54 public final ErrorType getErrorType() {
59 public final ErrorSeverity getSeverity() {
60 return ErrorSeverity.ERROR;
64 public final String getErrorTag() {
65 return "invalid-value";
69 public final Optional<String> getErrorAppTag() {
70 return Optional.ofNullable(errorAppTag);
74 public final Optional<String> getErrorMessage() {
75 return Optional.ofNullable(errorMessage);