Skip to content

Commit

Permalink
Refactor error handling and improve output messages in CLI commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Brijeshthummar02 committed Mar 7, 2025
1 parent 349b343 commit 108c398
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void handle() {
+ " "
+ Joiner.on(".").join(metalake, catalog, schema, table));
} catch (Exception exp) {
exitWithError("An error occurred while retrieving column details: " + exp.getMessage());
printResults("An error occurred while retrieving column details: " + exp.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ public ListTables(CommandContext context, String metalake, String catalog, Strin
/** List the names of all tables in a schema. */
@Override
public void handle() {
try {

Namespace name = Namespace.of(schema);
NameIdentifier[] tables = tableCatalog().listTables(name);

if (tables == null || tables.length == 0) {
printInformation("No tables exist.");
return;
}


try {
Table[] gTables = new Table[tables.length];
for (int i = 0; i < tables.length; i++) {
String tableName = tables[i].name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void handle() {
} catch (NoSuchTagException err) {
exitWithError(ErrorMessages.UNKNOWN_TAG);
} catch (Exception exp) {
exitWithError("An unexpected error occurred: " + exp.getMessage());
exitWithError(exp.getMessage());
}

if (gTag == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void handle() {
} catch (NoSuchModelException err) {
exitWithError(ErrorMessages.UNKNOWN_MODEL);
} catch (Exception err) {
exitWithError("An unexpected error occurred: " + err.getMessage());
exitWithError(err.getMessage());
}

if (gModel == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public void handle() {

if (result == null) {
exitWithError("Failed to retrieve schema details.");
return;
}

displayAuditInfo(result.auditInfo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ public void handle() {

try (GravitinoClient client = buildClient(metalake)) {
roles = client.getUser(user).roles();
} catch (NoSuchMetalakeException e) {
} catch (NoSuchMetalakeException err) {
exitWithError(ErrorMessages.UNKNOWN_METALAKE);
} catch (NoSuchUserException e) {
} catch (NoSuchUserException err) {
exitWithError(ErrorMessages.UNKNOWN_USER);
} catch (Exception e) {
exitWithError(e.getMessage());
} catch (Exception err) {
exitWithError(err.getMessage());
}

if (roles == null || roles.isEmpty()) {
printInformation("The user has no assigned roles.");
} else {
printResults("User Roles: " + String.join(", ", roles));
printResults(String.join(",", roles));
}
}
}

0 comments on commit 108c398

Please sign in to comment.