*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import java.io.File;
import java.io.IOException;
try {
statementContext = parseYangSource(loadFile(fileName, isAbsolute));
yangStatementModelParser = new YangStatementParserListenerImpl(sourceName);
- } catch (Exception e) {
- logError(e);
+ } catch (IOException | URISyntaxException | YangSyntaxErrorException e) {
+ throw Throwables.propagate(e);
}
}
try {
statementContext = parseYangSource(inputStream);
yangStatementModelParser = new YangStatementParserListenerImpl(sourceName);
- } catch (Exception e) {
- logError(e);
+ } catch (IOException | YangSyntaxErrorException e) {
+ throw Throwables.propagate(e);
}
}
public YangStatementSourceImpl(final SourceIdentifier identifier, final YangStatementParser.StatementContext statementContext) {
- try {
- this.statementContext = statementContext;
- this.sourceName = identifier.getName();
- yangStatementModelParser = new YangStatementParserListenerImpl(sourceName);
- } catch (Exception e) {
- logError(e);
- }
+ this.statementContext = statementContext;
+ this.sourceName = identifier.getName();
+ yangStatementModelParser = new YangStatementParserListenerImpl(sourceName);
}
@Override
public String toString() {
return sourceName;
}
-
- private static void logError(final Exception e) {
- if (e instanceof YangSyntaxErrorException) {
- LOG.error(((YangSyntaxErrorException) e).getFormattedMessage(), e);
- } else {
- LOG.error(e.getMessage(), e);
- }
- }
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.stmt;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+
+public class Bug7146Test {
+
+ @Test
+ public void shouldFailOnSyntaxError() throws ReactorException {
+ try {
+ StmtTestUtils.parseYangSources(new YangStatementSourceImpl("/bugs/bug7146/foo.yang", false));
+ fail("RuntimeException should have been thrown because of an unknown character in yang module.");
+ } catch (RuntimeException ex) {
+ final Throwable cause = ex.getCause();
+ assertTrue(cause instanceof YangSyntaxErrorException);
+ assertTrue(cause.getMessage().contains("extraneous input '#'"));
+ }
+ }
+}