Skip to content

Commit

Permalink
[api] Improves DJL URL error message (#2678)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfliu committed Jun 27, 2023
1 parent 68c7a03 commit f3d8626
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
10 changes: 6 additions & 4 deletions api/src/test/java/ai/djl/repository/DjlRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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://"));
Expand Down

0 comments on commit f3d8626

Please sign in to comment.