99import static seedu .address .logic .parser .CliSyntax .PREFIX_PARENT_PHONE ;
1010import static seedu .address .logic .parser .CliSyntax .PREFIX_TAG ;
1111
12+ import java .util .Arrays ;
13+ import java .util .HashSet ;
1214import java .util .Set ;
1315import java .util .logging .Logger ;
1416import java .util .stream .Stream ;
@@ -48,6 +50,12 @@ public AddCommand parse(String args) throws ParseException {
4850 PREFIX_NAME , PREFIX_AGE , PREFIX_ADDRESS ,
4951 PREFIX_PARENT_NAME , PREFIX_PARENT_PHONE , PREFIX_PARENT_EMAIL , PREFIX_TAG );
5052
53+ // Detect unsupported/unknown prefixes early and give clear error
54+ checkForUnsupportedPrefixes (args , PREFIX_NAME .toString (), PREFIX_AGE .toString (),
55+ PREFIX_ADDRESS .toString (), PREFIX_PARENT_NAME .toString (),
56+ PREFIX_PARENT_PHONE .toString (), PREFIX_PARENT_EMAIL .toString (),
57+ PREFIX_TAG .toString ());
58+
5159 // Ensure duplicate check includes parent fields too
5260 argMultimap .verifyNoDuplicatePrefixesFor (
5361 PREFIX_NAME , PREFIX_AGE , PREFIX_ADDRESS ,
@@ -58,7 +66,8 @@ public AddCommand parse(String args) throws ParseException {
5866 || !argMultimap .getPreamble ().isEmpty ()) {
5967 logger .warning ("Missing required prefixes or non-empty preamble in AddCommand. "
6068 + "User input: " + args );
61- throw new ParseException (String .format (MESSAGE_INVALID_COMMAND_FORMAT , AddCommand .MESSAGE_USAGE ));
69+ throw new ParseException (
70+ String .format (MESSAGE_INVALID_COMMAND_FORMAT , AddCommand .MESSAGE_USAGE ));
6271 }
6372
6473 Name name = ParserUtil .parseName (argMultimap .getValue (PREFIX_NAME ).get ());
@@ -88,4 +97,29 @@ private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Pre
8897 return Stream .of (prefixes ).allMatch (prefix -> argumentMultimap .getValue (prefix ).isPresent ());
8998 }
9099
100+ /**
101+ * Scans the raw arguments for any prefix-like tokens (e.g. "d/") that are not
102+ * in the
103+ * provided allowedPrefixes. Throws a ParseException with a clear message if any
104+ * unsupported prefix is found.
105+ */
106+ private static void checkForUnsupportedPrefixes (String args , String ... allowedPrefixes ) throws ParseException {
107+ if (args == null || args .isBlank ()) {
108+ return ;
109+ }
110+ Set <String > allowed = new HashSet <>(Arrays .asList (allowedPrefixes ));
111+ String [] tokens = args .trim ().split ("\\ s+" );
112+ for (String token : tokens ) {
113+ int slashIdx = token .indexOf ('/' );
114+ if (slashIdx > 0 ) {
115+ String candidatePrefix = token .substring (0 , slashIdx + 1 );
116+ if (!allowed .contains (candidatePrefix )) {
117+ // Clear, actionable error: show the unsupported prefix and usage
118+ throw new ParseException ("Unsupported prefix: " + candidatePrefix + "\n "
119+ + String .format (MESSAGE_INVALID_COMMAND_FORMAT ,
120+ AddCommand .MESSAGE_USAGE ));
121+ }
122+ }
123+ }
124+ }
91125}
0 commit comments