diff --git a/eo-parser/src/main/java/org/eolang/parser/StrictXmir.java b/eo-parser/src/main/java/org/eolang/parser/StrictXmir.java index edc2d12f67..de184ea936 100644 --- a/eo-parser/src/main/java/org/eolang/parser/StrictXmir.java +++ b/eo-parser/src/main/java/org/eolang/parser/StrictXmir.java @@ -182,8 +182,16 @@ private static File download(final String uri, final Path path) { new BytesOf(new InputOf(new URI(uri))) ).asBytes() ); - } catch (final IOException | URISyntaxException ex) { - throw new IllegalArgumentException(ex); + } catch (final IOException ex) { + throw new IllegalArgumentException( + String.format("Failed to download %s to %s", uri, path), + ex + ); + } catch (final URISyntaxException ex) { + throw new IllegalArgumentException( + String.format("Wrong URI: %s", uri), + ex + ); } } return abs; diff --git a/eo-parser/src/test/java/org/eolang/parser/StrictXmirTest.java b/eo-parser/src/test/java/org/eolang/parser/StrictXmirTest.java index a0e167b38e..b3a61d1dc2 100644 --- a/eo-parser/src/test/java/org/eolang/parser/StrictXmirTest.java +++ b/eo-parser/src/test/java/org/eolang/parser/StrictXmirTest.java @@ -29,6 +29,7 @@ import java.nio.file.Path; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.xembly.Directives; @@ -72,4 +73,29 @@ void validatesXmir(@Mktmp final Path tmp) throws Exception { ); } + @Test + @ExtendWith(MktmpResolver.class) + void validatesXmirWithBrokenUri(@Mktmp final Path tmp) { + Assertions.assertThrows( + IllegalArgumentException.class, + () -> new StrictXmir( + new Xmir( + new XMLDocument( + new Xembler( + new Directives() + .append(new DrProgram("foo")) + .xpath("/program") + .attr( + "noNamespaceSchemaLocation xsi http://www.w3.org/2001/XMLSchema-instance", + "https://www.invalid-website-uri/XMIR.xsd" + ) + .add("objects") + ).xml() + ) + ), + tmp + ).validate(), + "validation should fail because of broken URI" + ); + } }