Skip to content

Commit

Permalink
Merge pull request #104 from kokerinks/update-error-msgs
Browse files Browse the repository at this point in the history
Improved error messsages for each command
  • Loading branch information
billyhoce authored Apr 4, 2024
2 parents 51b57a9 + 1f35002 commit 3cf2364
Show file tree
Hide file tree
Showing 20 changed files with 83 additions and 64 deletions.
14 changes: 8 additions & 6 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
*/
public class Messages {

public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command. Type 'help -c' to see the list of commands.";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid.";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_PERSON_NOT_FOUND = "The specified person is not found";
public static final String MESSAGE_PERSON_NOT_FOUND = "The specified person is not found.";
public static final String MESSAGE_DUPLICATE_FIELDS =
"Multiple values specified for the following single-valued field(s): ";

Expand All @@ -43,9 +43,11 @@ public static String format(Person person) {
.append("; Email: ")
.append(person.getEmail())
.append("; Address: ")
.append(person.getAddress())
.append("; Allergens: ");
person.getAllergens().forEach(builder::append);
.append(person.getAddress());
if (person.getAllergens().isEmpty()) {
builder.append("; Allergens: ");
person.getAllergens().forEach(builder::append);
}
return builder.toString();
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_POINTS;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
Expand All @@ -20,20 +21,22 @@ public class AddCommand extends Command {

public static final String COMMAND_WORD = "addmem";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. \n"
+ "Parameters: "
+ PREFIX_NAME + "MEMBER_NAME "
+ PREFIX_PHONE + "MEMBER_PHONE "
+ PREFIX_EMAIL + "MEMBER_EMAIL "
+ PREFIX_ADDRESS + "MEMBER_ADDRESS "
+ "[" + PREFIX_POINTS + "POINTS] "
+ "[" + PREFIX_ALLERGENS + "ALLERGENS]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_POINTS + "100 "
+ PREFIX_ALLERGENS + "friends "
+ PREFIX_ALLERGENS + "owesMoney";
+ PREFIX_ALLERGENS + "owesMoney ";

public static final String MESSAGE_SUCCESS = "New person added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public class AddItemCommand extends Command {
public static final String COMMAND_WORD = "additem";
public static final String INVALID_COMMAND_FORMAT = "Invalid command format! ";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an item to the catalogue. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an item to the catalogue. \n"
+ "Parameters: "
+ PREFIX_ITEM + "ITEM_NAME "
+ PREFIX_POINTS + "POINTS_PER_UNIT\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_ITEM + "Chocolate Cake "
+ PREFIX_ITEM + "chocolate cake "
+ PREFIX_POINTS + "50";

public static final String MESSAGE_SUCCESS = "New item added: %1$s";
public static final String MESSAGE_DUPLICATE_ITEM = "This item already exists in the catalogue";
public static final String MESSAGE_DUPLICATE_ITEM = "This item already exists in the catalogue.";

private final Item toAdd;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ public class AddMemPointsCommand extends Command {
public static final String COMMAND_WORD = "addmempts";

public static final String INVALID_COMMAND_FORMAT = "Invalid command format.";
public static final String MESSAGE_CONSTRAINTS = "Points to add must be a positive integer";
public static final String MESSAGE_CONSTRAINTS = "Points to add must be a positive integer.";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Add membership points to the person identified "
+ "by the name of the person in the listing. "
+ "Existing membership will be overwritten by the input.\n"
+ "Parameters: n/MEMBER_NAME " + PREFIX_MEMSHIP_PTS + "[POINTS_TO_ADD]\n"
+ ": Add membership points to the person identified. "
+ "May upgrade the member's tier after adding points.\n"
+ "Parameters: n/MEMBER_NAME " + PREFIX_MEMSHIP_PTS + "POINTS_TO_ADD\n"
+ "Example: " + COMMAND_WORD + " n/Alice "
+ PREFIX_MEMSHIP_PTS + "T1";
+ PREFIX_MEMSHIP_PTS + "100";
public static final String MESSAGE_ADD_MEMBERSHIP_SUCCESS = "Added %1$d membership points to Person: %2$s";
private final Name name;
private final int pointsToAdd;
Expand All @@ -47,7 +46,7 @@ public CommandResult execute(Model model) throws CommandException {
List<Person> lastShownList = model.getFilteredPersonList();

Optional<Person> personOptional = lastShownList.stream()
.filter(person -> person.getName().equals(this.name))
.filter(person -> person.getName().fullName.toLowerCase().contains(this.name.fullName.toLowerCase()))
.findFirst();

if (personOptional.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public class AddOrderCommand extends Command {
public static final String COMMAND_WORD = "addorder";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Adds an order to the order list of the person identified by the given Name.\n"
+ ": Adds an order to the order list of the person identified by the given name.\n"
+ "Parameters: n/MEMBER_NAME i/ITEM_NAME [q/QUANTITY]\n"
+ "NOTE: If quantity is not specified, it will default to 1.\n"
+ "Example: " + COMMAND_WORD + " n/Alex Yeoh i/Chocolate Chip Cookies 100g q/3";

public static final String MESSAGE_ADD_ORDER_SUCCESS = "Added order to Person: %1$s";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public class AddPointsCommand extends Command {
public static final String MESSAGE_CONSTRAINTS = "Points added should be greater than 0.";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Adds points to the person identified. "
+ ": Adds points to the person identified. \n"
+ "Parameters: " + PREFIX_NAME + "NAME " + PREFIX_POINTS + "POINTS \n"
+ "Example: " + COMMAND_WORD + " " + PREFIX_NAME + " John Doe " + PREFIX_POINTS + "40";
+ "Example: " + COMMAND_WORD + " " + PREFIX_NAME + "John Doe " + PREFIX_POINTS + "40";
public static final String MESSAGE_ADDPOINTS_SUCCESS =
"Added %1$s points to %2$s";
private final Name name;
Expand Down Expand Up @@ -55,7 +55,7 @@ public CommandResult execute(Model model) throws CommandException {

if (personOptional.isEmpty()) {
throw new CommandException(
Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
Messages.MESSAGE_PERSON_NOT_FOUND);
}

Person personToEdit = personOptional.get();
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ public class ClearCommand extends Command {

public static final String COMMAND_WORD = "clear";
public static final String MESSAGE_SUCCESS = "Address book has been cleared!";
public static final String MESSAGE_CONFIRM = "Are you sure you want to clear the address book? Use\n"
+ "clear --force\n"
+ "to confirm clearing of the address book.";
public static final String MESSAGE_CONFIRM = "Are you sure you want to clear the address book? \n"
+ "Use `clear --force` to confirm clearing of the address book.";
private final boolean isForced;

public ClearCommand() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
*/
public class DeleteCommand extends Command {

public static final String COMMAND_WORD = "delete";
public static final String COMMAND_WORD = "delmem";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the person identified by the index number used in the displayed person list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Parameters: INDEX\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s";
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ public class EditCommand extends Command {
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified "
+ "by the index number used in the displayed person list. "
+ "Existing values will be overwritten by the input values.\n"
+ "Orders cannot be edited this way.\n"
+ "Parameters: INDEX (must be a positive integer) "
+ "NOTE: Orders cannot be edited this way.\n"
+ "Parameters: INDEX "
+ "[" + PREFIX_NAME + "MEMBER_NAME] "
+ "[" + PREFIX_PHONE + "MEMBER_PHONE] "
+ "[" + PREFIX_EMAIL + "MEMBER_EMAIL] "
+ "[" + PREFIX_ADDRESS + "MEMBER_ADDRESS] "
+ "[" + PREFIX_ALLERGENS + "ALLERGENS]"
+ "[" + PREFIX_POINTS + "POINTS]...\n"
+ "[" + PREFIX_ADDRESS + "MEMBER_ADDRESS] \n"
+ "\t\t\t[" + PREFIX_ALLERGENS + "ALLERGENS] "
+ "[" + PREFIX_POINTS + "POINTS] "
+ "[" + PREFIX_MEMSHIP_PTS + "MEMBERSHIP_POINTS]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
+ PREFIX_EMAIL + "[email protected]";
+ PREFIX_EMAIL + "[email protected]\n";

public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/seedu/address/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ public class FindCommand extends Command {

public static final String COMMAND_WORD = "find";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose names contain any of "
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n"
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Displays all persons whose names contain ANY of "
+ "the specified keywords (case-insensitive)\n"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " alice bob charlie";

public static final String MESSAGE_NO_PERSONS_FOUND = "No persons found! Showing all persons instead.";

private final NameContainsKeywordsPredicate predicate;

public FindCommand(NameContainsKeywordsPredicate predicate) {
Expand All @@ -30,6 +32,10 @@ public FindCommand(NameContainsKeywordsPredicate predicate) {
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList(predicate);
if (model.getFilteredPersonList().isEmpty()) {
model.updateFilteredPersonList(Model.PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(MESSAGE_NO_PERSONS_FOUND);
}
return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size()));
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/seedu/address/logic/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,28 @@ public class HelpCommand extends Command {
public static final String COMMAND_WORD = "help";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Shows program usage instructions.\n"
+ "Parameters: [--commands/-c]\n"
+ "Example: " + COMMAND_WORD;

public static final String SHOWING_HELP_MESSAGE = "Opened help window.";

public static final String INVALID_FLAG_MESSAGE = "The flag `%s` is invalid.";

public static final String COMMAND_LIST = "Command List " + "\n"
+ AddCommand.COMMAND_WORD + " : Add a member" + "\n"
+ AddItemCommand.COMMAND_WORD + " : Add item" + "\n"
+ AddMemPointsCommand.COMMAND_WORD + " : Add membership points" + "\n"
+ AddPointsCommand.COMMAND_WORD + " : Add redemption points" + "\n"
+ AddOrderCommand.COMMAND_WORD + " : Add order" + "\n"
+ AddItemCommand.COMMAND_WORD + " : Add item" + "\n"
+ DeleteItemCommand.COMMAND_WORD + " : Delete item" + "\n"
+ RedeemPointsCommand.COMMAND_WORD + " : Redeem points" + "\n"
+ AddPointsCommand.COMMAND_WORD + " : Add redemption points" + "\n"
+ ClearCommand.COMMAND_WORD + " : Clear all members" + "\n"
+ DeleteCommand.COMMAND_WORD + " : Delete a member" + "\n"
+ DeleteItemCommand.COMMAND_WORD + " : Delete item" + "\n"
+ EditCommand.COMMAND_WORD + " : Edit member details" + "\n"
+ ExitCommand.COMMAND_WORD + " : Exit the program" + "\n"
+ FindCommand.COMMAND_WORD + " : Find members" + "\n"
+ HelpCommand.COMMAND_WORD + " : Access user guide" + "\n"
+ ListCommand.COMMAND_WORD + " : List all members" + "\n"
+ RedeemPointsCommand.COMMAND_WORD + " : Redeem points" + "\n"
+ SeedDataCommand.COMMAND_WORD + " : Seed data";

private String helpType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public class RedeemPointsCommand extends Command {
public static final String MESSAGE_CONSTRAINTS = "Points to redeem should be greater than 0.";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Redeems points from the person identified. "
+ ": Redeems points from the person identified. \n"
+ "Parameters: " + PREFIX_NAME + "NAME " + PREFIX_POINTS + "POINTS \n"
+ "Example: " + COMMAND_WORD + " John Doe " + PREFIX_POINTS + "30";
+ "Example: " + COMMAND_WORD + " " + PREFIX_NAME + "John Doe " + PREFIX_POINTS + "30";

public static final String MESSAGE_REDEEMPOINTS_SUCCESS =
"Redeemed %1$s points from %2$s";
public static final String MESSAGE_INSUFFICIENT_POINTS =
"Insufficient points. Current points: %1$s";
"%s has insufficient points (%s pts) to redeem.";

private final Name name;
private final Points pointsToRedeem;
Expand Down Expand Up @@ -66,7 +66,8 @@ public CommandResult execute(Model model) throws CommandException {
int pointsToRedeemValue = this.pointsToRedeem.getValue();

if (currentPointsValue < pointsToRedeemValue) {
throw new CommandException(String.format(MESSAGE_INSUFFICIENT_POINTS, currentPointsValue));
throw new CommandException(
String.format(MESSAGE_INSUFFICIENT_POINTS, personToEdit.getName(), currentPointsValue));
}

Points newPoints = new Points(Integer.toString(currentPointsValue - pointsToRedeemValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public AddMemPointsCommand parse(String args) throws ParseException {
try {
pointsToAdd = ParserUtil.parseMemPointsToAdd(argMultimap.getValue(PREFIX_MEMSHIP_PTS).orElse(""));
} catch (ParseException pe) {
throw new ParseException(AddMemPointsCommand.MESSAGE_CONSTRAINTS
+ "\n" + AddMemPointsCommand.MESSAGE_USAGE);
throw new ParseException(AddMemPointsCommand.MESSAGE_CONSTRAINTS);
}

return new AddMemPointsCommand(name, pointsToAdd);
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/seedu/address/logic/parser/HelpCommandParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.parser;

import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
* Parses input arguments and creates a new HelpCommand object
Expand All @@ -12,8 +13,11 @@ public class HelpCommandParser implements Parser<HelpCommand> {
* @param args the user input string
* @return the parsed HelpCommand object
*/
public HelpCommand parse(String args) {
public HelpCommand parse(String args) throws ParseException {
args = args.trim();
if (args.isEmpty()) {
return new HelpCommand();
}
String[] argsList = args.split(" ");
String commandType = null;
for (String arg : argsList) {
Expand All @@ -24,13 +28,10 @@ public HelpCommand parse(String args) {
commandType = "commands";
break;
default:
break;
throw new ParseException(String.format(HelpCommand.INVALID_FLAG_MESSAGE, arg) + "\n"
+ HelpCommand.MESSAGE_USAGE);
}
}
if (commandType == null) {
return new HelpCommand();
} else {
return new HelpCommand(commandType);
}
return new HelpCommand(commandType);
}
}
3 changes: 2 additions & 1 deletion src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -61,7 +62,7 @@ public void execute_invalidCommandFormat_throwsParseException() {

@Test
public void execute_commandExecutionError_throwsCommandException() {
String deleteCommand = "delete 9";
String deleteCommand = DeleteCommand.COMMAND_WORD + " 9";
assertCommandException(deleteCommand, MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void execute_invalidPersonNameUnfilteredList_failure() {
Name outOfBoundName = new Name("Nonexistent Name");
AddPointsCommand addPointsCommand = new AddPointsCommand(outOfBoundName, new Points(POINTS_STUB));

assertCommandFailure(addPointsCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
assertCommandFailure(addPointsCommand, model, Messages.MESSAGE_PERSON_NOT_FOUND);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ public void equals() {

@Test
public void execute_zeroKeywords_noPersonFound() {
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0);
String expectedMessage = FindCommand.MESSAGE_NO_PERSONS_FOUND;
NameContainsKeywordsPredicate predicate = preparePredicate(" ");
FindCommand command = new FindCommand(predicate);
expectedModel.updateFilteredPersonList(predicate);
expectedModel.updateFilteredPersonList(Model.PREDICATE_SHOW_ALL_PERSONS);
assertCommandSuccess(command, model, expectedMessage, expectedModel);
assertEquals(Collections.emptyList(), model.getFilteredPersonList());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void parse_missingMembershipPoints_failure() {

@Test
public void parse_invalidMembershipPoints_failure() {
String expectedMessage = AddMemPointsCommand.MESSAGE_CONSTRAINTS + "\n" + AddMemPointsCommand.MESSAGE_USAGE;
String expectedMessage = AddMemPointsCommand.MESSAGE_CONSTRAINTS;
assertParseFailure(parser, " n/Alice " + PREFIX_MEMSHIP_PTS + "abc", expectedMessage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public void parseCommand_find() throws Exception {
@Test
public void parseCommand_help() throws Exception {
assertTrue(parser.parseCommand(HelpCommand.COMMAND_WORD) instanceof HelpCommand);
assertTrue(parser.parseCommand(HelpCommand.COMMAND_WORD + " 3") instanceof HelpCommand);
}

@Test
Expand Down
Loading

0 comments on commit 3cf2364

Please sign in to comment.