/**
* An error preventing an operation from completing successfully.
*/
- ERROR("error", RpcError.ErrorSeverity.ERROR),
+ ERROR("error"),
/**
* A warning not affecting an operation's ability to complete successfully.
*/
- WARNING("warning", RpcError.ErrorSeverity.ERROR);
+ WARNING("warning");
private static final Map<String, ErrorSeverity> BY_ELEMENT_BODY =
Maps.uniqueIndex(Arrays.asList(values()), ErrorSeverity::elementBody);
- private final RpcError.ErrorSeverity legacy;
private final String elementBody;
- ErrorSeverity(final String elementName, final RpcError.ErrorSeverity legacy) {
+ ErrorSeverity(final String elementName) {
this.elementBody = requireNonNull(elementName);
- this.legacy = requireNonNull(legacy);
}
/**
return elementBody;
}
- @Deprecated
- public RpcError.ErrorSeverity toLegacy() {
- return legacy;
- }
-
public static @Nullable ErrorSeverity forElementBody(final String elementBody) {
return BY_ELEMENT_BODY.get(requireNonNull(elementBody));
}
* A {@link NetconfLayer#TRANSPORT} layer error. This typically happens on transport endpoints, where a protocol
* plugin needs to report a NETCONF-equivalent condition.
*/
- TRANSPORT("transport", NetconfLayer.TRANSPORT, RpcError.ErrorType.TRANSPORT),
+ TRANSPORT("transport", NetconfLayer.TRANSPORT),
/**
* A {@link NetconfLayer#RPC} layer error. This typically happens on request routers, where a request may end up
* being resolved due to implementation-internal causes, such as timeouts and state loss.
*/
- RPC("rpc", NetconfLayer.RPC, RpcError.ErrorType.RPC),
+ RPC("rpc", NetconfLayer.RPC),
/**
* A {@link NetconfLayer#OPERATIONS} layer error. These typically happen in a NETCONF protocol implementation.
*/
- PROTOCOL("protocol", NetconfLayer.OPERATIONS, RpcError.ErrorType.PROTOCOL),
+ PROTOCOL("protocol", NetconfLayer.OPERATIONS),
/**
* A {@link NetconfLayer#CONTENT} layer error. These typically happen due to YANG data handling, such as
* type checking and structural consistency.
*/
- APPLICATION("application", NetconfLayer.CONTENT, RpcError.ErrorType.APPLICATION);
+ APPLICATION("application", NetconfLayer.CONTENT);
private static final Map<String, ErrorType> BY_ELEMENT_BODY =
Maps.uniqueIndex(Arrays.asList(values()), ErrorType::elementBody);
- private final RpcError.ErrorType legacy;
private final String elementBody;
private final NetconfLayer layer;
- ErrorType(final String elementName, final NetconfLayer layer, final RpcError.ErrorType legacy) {
+ ErrorType(final String elementName, final NetconfLayer layer) {
this.elementBody = requireNonNull(elementName);
this.layer = requireNonNull(layer);
- this.legacy = requireNonNull(legacy);
}
/**
return layer;
}
- @Deprecated
- public final RpcError.ErrorType toLegacy() {
- return legacy;
- }
-
public static @Nullable ErrorType forElementBody(final String elementBody) {
return BY_ELEMENT_BODY.get(requireNonNull(elementBody));
}
*/
public enum NetconfLayer {
/**
- * Content layer, for example configuration data. This layer is implied indirectly in constructs defined in
- * {@link YangError} and corresponds to {@link ErrorType#APPLICATION}
+ * Content layer, for example configuration data. This layer is implied indirectly in all YANG-based validation and
+ * corresponds to {@link ErrorType#APPLICATION}
*/
CONTENT,
/**
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
/**
* A general base exception for an operation failure.
*/
package org.opendaylight.yangtools.yang.common;
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
/**
* Representation of an error.
*/
public interface RpcError {
- // FIXME: 8.0.0: remove this in favor of Netconf.ErrorSeverity
- @NonNullByDefault
- enum ErrorSeverity {
- ERROR {
- @Override
- public org.opendaylight.yangtools.yang.common.ErrorSeverity toNetconf() {
- return org.opendaylight.yangtools.yang.common.ErrorSeverity.ERROR;
- }
- },
- WARNING {
- @Override
- public org.opendaylight.yangtools.yang.common.ErrorSeverity toNetconf() {
- return org.opendaylight.yangtools.yang.common.ErrorSeverity.WARNING;
- }
- };
-
- public abstract org.opendaylight.yangtools.yang.common.ErrorSeverity toNetconf();
- }
-
- /**
- * Enumeration of {@code error-type} values. These provide glue between {@link NetconfLayer} and various sources of
- * such errors.
- */
- // FIXME: 8.0.0: remove this in favor of common.ErrorType
- @NonNullByDefault
- enum ErrorType {
- /**
- * Indicates an error occurred during transport of data, eg over the network.
- */
- TRANSPORT {
- @Override
- public org.opendaylight.yangtools.yang.common.ErrorType toNetconf() {
- return org.opendaylight.yangtools.yang.common.ErrorType.TRANSPORT;
- }
- },
- /**
- * Indicates an error occurred during a remote procedure call.
- */
- RPC {
- @Override
- public org.opendaylight.yangtools.yang.common.ErrorType toNetconf() {
- return org.opendaylight.yangtools.yang.common.ErrorType.RPC;
- }
- },
- /**
- * Indicates an error at a protocol layer, eg if invalid data was passed by the caller.
- */
- PROTOCOL {
- @Override
- public org.opendaylight.yangtools.yang.common.ErrorType toNetconf() {
- return org.opendaylight.yangtools.yang.common.ErrorType.PROTOCOL;
- }
- },
- /**
- * Indicates an error occurred during internal processing.
- */
- APPLICATION {
- @Override
- public org.opendaylight.yangtools.yang.common.ErrorType toNetconf() {
- return org.opendaylight.yangtools.yang.common.ErrorType.APPLICATION;
- }
- };
-
- public abstract org.opendaylight.yangtools.yang.common.ErrorType toNetconf();
- }
-
/**
* Returns the error severity, as determined by the application reporting the error.
*
import java.util.Collection;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Builder;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
/**
* A builder for creating RpcResult instances.
+++ /dev/null
-/*
- * 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.
- *
- * @deprecated This interface is not completely sufficient to describe errors, as it lacks the ability to carry instance
- * path as well as more-info elements.
- */
-@Beta
-@Deprecated(forRemoval = true, since = "7.0.4")
-// FIXME: 8.0.0: remove this class
-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 error tag, as determined by the application reporting the error.
- *
- * @return an error tag.
- */
- @NonNull String getErrorTag();
-
- /**
- * Returns the value of the argument of YANG {@code error-app-tag} statement.
- *
- * @return string with the application error tag, or empty if it was not provided.
- */
- Optional<String> getErrorAppTag();
-
- /**
- * Returns the value of the argument of YANG {@code error-message} statement.
- *
- * @return string with the error message, or empty if it was not provided.
- */
- Optional<String> getErrorMessage();
-}
*/
package org.opendaylight.yangtools.yang.common;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class OperationFailedExceptionTest {
-
@Test
public void testOperationFailedException() {
final Throwable cause = new Throwable("mock cause");
- final RpcError rpcErrorShort = RpcResultBuilder.newError(RpcError.ErrorType.RPC, "tag", "msg");
+ final RpcError rpcErrorShort = RpcResultBuilder.newError(ErrorType.RPC, "tag", "msg");
final OperationFailedException operationFailedException1 = new OperationFailedException("error msg", cause,
rpcErrorShort);
final OperationFailedException operationFailedException2 = new OperationFailedException("error msg",
rpcErrorShort);
assertEquals(operationFailedException1.getErrorList(), operationFailedException2.getErrorList());
- assertTrue(operationFailedException1.toString().contains("error msg"));
+ assertThat(operationFailedException1.toString(), containsString("error msg"));
}
}
* 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 static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
/**
* Unit tests for RpcResultBuilder.
@Test
public void testErrors() {
final RpcResultBuilder<Object> rpcResultBuilder = RpcResultBuilder.status(true);
- final RpcError rpcErrorShort = RpcResultBuilder.newError(RpcError.ErrorType.RPC, "tag", "msg");
- final RpcError rpcErrorLong = RpcResultBuilder.newError(RpcError.ErrorType.RPC, "tag", "msg", "applicationTag",
+ final RpcError rpcErrorShort = RpcResultBuilder.newError(ErrorType.RPC, "tag", "msg");
+ final RpcError rpcErrorLong = RpcResultBuilder.newError(ErrorType.RPC, "tag", "msg", "applicationTag",
"info", null);
- final RpcError rpcErrorShortWarn = RpcResultBuilder.newWarning(RpcError.ErrorType.RPC, "tag", "msg");
- final RpcError rpcErrorLongWarn = RpcResultBuilder.newWarning(RpcError.ErrorType.RPC, "tag", "msg",
- "applicationTag",
+ final RpcError rpcErrorShortWarn = RpcResultBuilder.newWarning(ErrorType.RPC, "tag", "msg");
+ final RpcError rpcErrorLongWarn = RpcResultBuilder.newWarning(ErrorType.RPC, "tag", "msg", "applicationTag",
"info", null);
rpcResultBuilder.withRpcError(rpcErrorShort);
final RpcResult<Object> rpcResult = rpcResultBuilder.build();
import com.google.common.annotations.Beta;
import java.util.List;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.ErrorTag;
-import org.opendaylight.yangtools.yang.common.RpcError;
-import org.opendaylight.yangtools.yang.common.YangError;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.data.api.ImmutableYangNetconfError;
import org.opendaylight.yangtools.yang.data.api.YangNetconfError;
import org.opendaylight.yangtools.yang.data.api.YangNetconfErrorAware;
* which defines the appropriate severity and adds more semantics.
*/
@Beta
-public class YangInvalidValueException extends IllegalArgumentException implements YangError, YangNetconfErrorAware {
+public class YangInvalidValueException extends IllegalArgumentException implements YangNetconfErrorAware {
private static final long serialVersionUID = 1L;
- private final RpcError.@NonNull ErrorType errorType;
+ private final @NonNull ErrorType errorType;
private final @Nullable String errorAppTag;
private final @Nullable String errorMessage;
- public YangInvalidValueException(final RpcError.ErrorType errorType, final ConstraintMetaDefinition constraint,
+ public YangInvalidValueException(final ErrorType errorType, final ConstraintMetaDefinition constraint,
final String message) {
super(requireNonNull(message));
this.errorType = requireNonNull(errorType);
this.errorMessage = constraint.getErrorMessage().orElse(null);
}
- @Deprecated
- @Override
- public final RpcError.ErrorType getErrorType() {
- return errorType;
- }
-
- @Deprecated
- @Override
- public final RpcError.ErrorSeverity getSeverity() {
- return RpcError.ErrorSeverity.ERROR;
- }
-
- @Deprecated
- @Override
- public final String getErrorTag() {
- return "invalid-value";
- }
-
- @Deprecated
- @Override
- public final Optional<String> getErrorAppTag() {
- return Optional.ofNullable(errorAppTag);
- }
-
- @Deprecated
- @Override
- public final Optional<String> getErrorMessage() {
- return Optional.ofNullable(errorMessage);
- }
-
@Override
public List<YangNetconfError> getNetconfErrors() {
return List.of(ImmutableYangNetconfError.builder()
.severity(ErrorSeverity.ERROR)
- .type(errorType.toNetconf())
+ .type(errorType)
.tag(ErrorTag.INVALID_VALUE)
.message(errorMessage)
.appTag(errorAppTag)
import java.util.Optional;
import java.util.regex.Pattern;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.Uint16;
import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.common.Uint64;
}
private static int provideBase(final String integer) {
- if ((integer.length() == 1 && integer.charAt(0) == '0') || INT_PATTERN.matcher(integer).matches()) {
+ if (integer.length() == 1 && integer.charAt(0) == '0' || INT_PATTERN.matcher(integer).matches()) {
return 10;
} else if (HEX_PATTERN.matcher(integer).matches()) {
return 16;
import com.google.common.annotations.Beta;
import com.google.common.collect.RangeSet;
import java.util.Base64;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.data.api.codec.BinaryCodec;
import org.opendaylight.yangtools.yang.data.api.codec.YangInvalidValueException;
import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
import java.util.Optional;
import java.util.regex.Pattern;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.data.api.codec.YangInvalidValueException;
import org.opendaylight.yangtools.yang.model.api.type.ModifierKind;
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import com.google.common.annotations.Beta;
import com.google.common.collect.RangeSet;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.data.api.codec.StringCodec;
import org.opendaylight.yangtools.yang.data.api.codec.YangInvalidValueException;
import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;