From f3d8626941694a7e779e0b8630b48bc415abf04e Mon Sep 17 00:00:00 2001 From: Frank Liu Date: Tue, 27 Jun 2023 10:43:40 -0700 Subject: [PATCH] [api] Improves DJL URL error message (#2678) --- .../java/ai/djl/repository/RepositoryFactoryImpl.java | 6 ++---- .../test/java/ai/djl/repository/DjlRepositoryTest.java | 10 ++++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/api/src/main/java/ai/djl/repository/RepositoryFactoryImpl.java b/api/src/main/java/ai/djl/repository/RepositoryFactoryImpl.java index 7b6c3b7c995..71f394d6d14 100644 --- a/api/src/main/java/ai/djl/repository/RepositoryFactoryImpl.java +++ b/api/src/main/java/ai/djl/repository/RepositoryFactoryImpl.java @@ -253,14 +253,12 @@ public Repository newInstance(String name, URI uri) { ModelZoo zoo = ModelZoo.getModelZoo(groupId); if (zoo == null) { - logger.warn("ModelZoo not found: {}", groupId); - return repo; + throw new IllegalArgumentException("ModelZoo not found in classpath: " + groupId); } ModelLoader loader = zoo.getModelLoader(artifactId); if (loader == null) { - logger.warn("Artifact not found: {}/{}", groupId, artifactId); - return repo; + throw new IllegalArgumentException("Invalid djl URL: " + uri); } MRL mrl = diff --git a/api/src/test/java/ai/djl/repository/DjlRepositoryTest.java b/api/src/test/java/ai/djl/repository/DjlRepositoryTest.java index 24a0b1c6cc5..5a53da4f46d 100644 --- a/api/src/test/java/ai/djl/repository/DjlRepositoryTest.java +++ b/api/src/test/java/ai/djl/repository/DjlRepositoryTest.java @@ -37,11 +37,13 @@ public void testResource() throws ModelNotFoundException, MalformedModelExceptio repo = Repository.newInstance("DJL", "djl://ai.djl.pytorch/resnet/0.0.1/traced_resnet18"); Assert.assertEquals(repo.getResources().size(), 1); - repo = Repository.newInstance("DJL", "djl://ai.djl.pytorch/fake/0.0.1"); - Assert.assertEquals(repo.getResources().size(), 0); + Assert.assertThrows( + IllegalArgumentException.class, + () -> Repository.newInstance("DJL", "djl://ai.djl.pytorch/fake/0.0.1")); - repo = Repository.newInstance("DJL", "djl://ai.djl.fake/mlp/0.0.1"); - Assert.assertEquals(repo.getResources().size(), 0); + Assert.assertThrows( + IllegalArgumentException.class, + () -> Repository.newInstance("DJL", "djl://ai.djl.fake/mlp/0.0.1")); Assert.expectThrows( IllegalArgumentException.class, () -> Repository.newInstance("DJL", "djl://"));