Skip to content

Commit

Permalink
[apache#5830] fix(client): add error handling for no tag in cli. (apa…
Browse files Browse the repository at this point in the history
…che#5857)

### What changes were proposed in this pull request?

Add error handle with a friendly output for no tags command line.

### Why are the changes needed?

Now it throws an exception and may make customer confused.

Fix: apache#5830 

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Unit tests have been attached.
  • Loading branch information
LindaSummer authored Dec 17, 2024
1 parent 8021812 commit 530cd95
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ public CreateTag(
/** Create tags. */
@Override
public void handle() {
boolean hasOnlyOneTag = tags.length == 1;
if (hasOnlyOneTag) {
handleOnlyOneTag();
if (tags == null || tags.length == 0) {
System.err.println(ErrorMessages.TAG_EMPTY);
} else {
handleMultipleTags();
boolean hasOnlyOneTag = tags.length == 1;
if (hasOnlyOneTag) {
handleOnlyOneTag();
} else {
handleMultipleTags();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@ public void handle() {
if (!AreYouSure.really(force)) {
return;
}
boolean hasOnlyOneTag = tags.length == 1;
if (hasOnlyOneTag) {
handleOnlyOneTag();

if (tags == null || tags.length == 0) {
System.err.println(ErrorMessages.TAG_EMPTY);
} else {
handleMultipleTags();
boolean hasOnlyOneTag = tags.length == 1;
if (hasOnlyOneTag) {
handleOnlyOneTag();
} else {
handleMultipleTags();
}
}
}

Expand Down
20 changes: 20 additions & 0 deletions clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,24 @@ public void catalogWithOneArg() throws ParseException {
String entity = Main.resolveEntity(line);
assertEquals(CommandEntities.CATALOG, entity);
}

@Test
@SuppressWarnings("DefaultCharset")
public void CreateTagWithNoTag() {
String[] args = {"tag", "create", "--metalake", "metalake_test_no_tag"};

Main.main(args);

assertTrue(errContent.toString().contains(ErrorMessages.TAG_EMPTY)); // Expect error
}

@Test
@SuppressWarnings("DefaultCharset")
public void DeleteTagWithNoTag() {
String[] args = {"tag", "delete", "--metalake", "metalake_test_no_tag", "-f"};

Main.main(args);

assertTrue(errContent.toString().contains(ErrorMessages.TAG_EMPTY)); // Expect error
}
}

0 comments on commit 530cd95

Please sign in to comment.