From d45a58c9dab659631af359d2754c060d1dc832bc Mon Sep 17 00:00:00 2001 From: Ondre Tann Date: Thu, 11 Apr 2024 04:19:08 +0800 Subject: [PATCH] Fix id bug --- src/main/java/seedu/address/commons/util/AppUtil.java | 2 +- .../logic/parser/DeleteConfirmationCommandParser.java | 4 +++- .../java/seedu/address/logic/parser/EditCommandParser.java | 2 ++ .../java/seedu/address/logic/parser/TagCommandParser.java | 2 ++ .../address/logic/parser/TransactionCommandParser.java | 7 ++++++- .../java/seedu/address/logic/parser/ViewCommandParser.java | 2 ++ src/main/java/seedu/address/model/person/Id.java | 2 +- 7 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/commons/util/AppUtil.java b/src/main/java/seedu/address/commons/util/AppUtil.java index 87aa89c0326..bb8467e0fcd 100644 --- a/src/main/java/seedu/address/commons/util/AppUtil.java +++ b/src/main/java/seedu/address/commons/util/AppUtil.java @@ -34,7 +34,7 @@ public static void checkArgument(Boolean condition) { * * @throws IllegalArgumentException with {@code errorMessage} if {@code condition} is false. */ - public static void checkArgument(Boolean condition, String errorMessage) { + public static void checkArgument(Boolean condition, String errorMessage) throws IllegalArgumentException { if (!condition) { throw new IllegalArgumentException(errorMessage); } diff --git a/src/main/java/seedu/address/logic/parser/DeleteConfirmationCommandParser.java b/src/main/java/seedu/address/logic/parser/DeleteConfirmationCommandParser.java index c305ae3127b..73c690ea530 100644 --- a/src/main/java/seedu/address/logic/parser/DeleteConfirmationCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/DeleteConfirmationCommandParser.java @@ -13,13 +13,15 @@ public class DeleteConfirmationCommandParser implements Parser { @Override - public DeleteConfirmationCommand parse(String args) throws ParseException { + public DeleteConfirmationCommand parse(String args) throws ParseException, IllegalArgumentException { try { Id id = ParserUtil.parseId(args); return new DeleteConfirmationCommand(id); } catch (ParseException pe) { throw new ParseException( String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteCommand.MESSAGE_USAGE), pe); + } catch (IllegalArgumentException e) { + throw new ParseException(Id.MESSAGE_CONSTRAINTS); } } diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 84d741a3198..ac9e2924443 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -36,6 +36,8 @@ public EditCommand parse(String args) throws ParseException { id = ParserUtil.parseId(argMultimap.getPreamble()); } catch (ParseException pe) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe); + } catch (IllegalArgumentException e) { + throw new ParseException(Id.MESSAGE_CONSTRAINTS); } argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS); diff --git a/src/main/java/seedu/address/logic/parser/TagCommandParser.java b/src/main/java/seedu/address/logic/parser/TagCommandParser.java index 2072d900c32..5083d71f356 100644 --- a/src/main/java/seedu/address/logic/parser/TagCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/TagCommandParser.java @@ -34,6 +34,8 @@ public TagCommand parse(String args) throws ParseException { id = ParserUtil.parseId(argMultimap.getPreamble()); } catch (ParseException pe) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, TagCommand.MESSAGE_USAGE)); + } catch (IllegalArgumentException e) { + throw new ParseException(Id.MESSAGE_CONSTRAINTS); } Set tagNames = new HashSet<>(argMultimap.getAllValues(PREFIX_TAG)); diff --git a/src/main/java/seedu/address/logic/parser/TransactionCommandParser.java b/src/main/java/seedu/address/logic/parser/TransactionCommandParser.java index 8a19b3fd6ae..6c64ef618b0 100644 --- a/src/main/java/seedu/address/logic/parser/TransactionCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/TransactionCommandParser.java @@ -59,7 +59,12 @@ public TransactionCommand parse(String args) throws ParseException { } else { dateTime = new DateTime(LocalDateTime.now()); } - Id employeeId = ParserUtil.parseId(argMultimap.getValue(PREFIX_ID).get()); + Id employeeId = null; + try { + employeeId = ParserUtil.parseId(argMultimap.getValue(PREFIX_ID).get()); + } catch (IllegalArgumentException e) { + throw new ParseException(Id.MESSAGE_CONSTRAINTS); + } if (!model.hasPersonId(employeeId)) { throw new ParseException(MESSAGE_INVALID_PERSON_DISPLAYED_ID); } diff --git a/src/main/java/seedu/address/logic/parser/ViewCommandParser.java b/src/main/java/seedu/address/logic/parser/ViewCommandParser.java index 4f40e0834b4..5a6e17072e3 100644 --- a/src/main/java/seedu/address/logic/parser/ViewCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ViewCommandParser.java @@ -18,6 +18,8 @@ public ViewCommand parse(String userInput) throws ParseException { } catch (ParseException pe) { throw new ParseException( String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE), pe); + } catch (IllegalArgumentException e) { + throw new ParseException(Id.MESSAGE_CONSTRAINTS); } } } diff --git a/src/main/java/seedu/address/model/person/Id.java b/src/main/java/seedu/address/model/person/Id.java index 127d66ca3d6..5eb1c78bef1 100644 --- a/src/main/java/seedu/address/model/person/Id.java +++ b/src/main/java/seedu/address/model/person/Id.java @@ -35,7 +35,7 @@ public Id(Model model, YearJoined yearJoined) { * * @param id A valid ID. */ - public Id(int id) { + public Id(int id) throws IllegalArgumentException { checkArgument(isValidId(id), MESSAGE_CONSTRAINTS); value = id; }