Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize error message for inputs with valid command format but invalid index #161

Merged
merged 11 commits into from
Nov 8, 2020

Conversation

rnmy
Copy link

@rnmy rnmy commented Nov 4, 2020

closes #113, #122

@codecov-io
Copy link

codecov-io commented Nov 4, 2020

Codecov Report

Merging #161 (05cb0a3) into master (9ff5f50) will decrease coverage by 0.35%.
The diff coverage is 48.14%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #161      +/-   ##
============================================
- Coverage     73.61%   73.25%   -0.36%     
- Complexity      637      639       +2     
============================================
  Files           100      100              
  Lines          1944     1959      +15     
  Branches        225      226       +1     
============================================
+ Hits           1431     1435       +4     
- Misses          424      434      +10     
- Partials         89       90       +1     
Impacted Files Coverage Δ Complexity Δ
...in/java/seedu/address/commons/util/StringUtil.java 75.00% <0.00%> (-19.74%) 7.00 <0.00> (ø)
...ress/logic/parser/ShowAttendanceCommandParser.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...eedu/address/logic/parser/DeleteCommandParser.java 70.00% <50.00%> (-30.00%) 2.00 <1.00> (ø)
.../seedu/address/logic/parser/EditCommandParser.java 93.93% <100.00%> (+0.83%) 14.00 <1.00> (+2.00)
...in/java/seedu/address/logic/parser/ParserUtil.java 89.55% <100.00%> (ø) 25.00 <0.00> (ø)
...du/address/logic/parser/UnattendCommandParser.java 100.00% <100.00%> (ø) 4.00 <0.00> (ø)
...java/seedu/address/logic/commands/EditCommand.java 93.90% <0.00%> (-1.22%) 12.00% <0.00%> (ø%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ff5f50...05cb0a3. Read the comment docs.


/**
* Parses {@code oneBasedIndex} into an {@code Index} and returns it. Leading and trailing whitespaces will be
* trimmed.
* @throws ParseException if the specified index is invalid (not non-zero unsigned integer).
*/
public static Index parseIndex(String oneBasedIndex) throws ParseException {
public static Index parseIndex(String oneBasedIndex) throws CommandException, ParseException {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only throw ParseException in this function.

CommandException is used for errors which occur during execurtion of a command.

ParserException Represents a parse error encountered by a parser.

In this case, the error occurs during the parsing stage when the users passes in -1.

Copy link

@kwannoel kwannoel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes

if (!StringUtil.isNonZeroUnsignedInteger(trimmedIndex)) {
if (StringUtil.isInteger(trimmedIndex) && !StringUtil.isNonZeroUnsignedInteger(trimmedIndex)) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
} else if (!StringUtil.isNonZeroUnsignedInteger(trimmedIndex)) {
throw new ParseException(MESSAGE_INVALID_INDEX);
}
return Index.fromOneBased(Integer.parseInt(trimmedIndex));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a redundancy here,

we called Integer.parseInt twice,

once in StringUtil.isInteger and once in this line.

This is because the parser is structured in a "validate first, then parse".

Would suggest a parse dont validate approach instead: https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/

Copy link

@kwannoel kwannoel Nov 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more of a FYI, up to you if you want to pull the change in :)

Copy link

@chrisgzf chrisgzf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as Noel else LGTM!

@rnmy rnmy linked an issue Nov 8, 2020 that may be closed by this pull request
Copy link

@kwannoel kwannoel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebase against master

@chrisgzf chrisgzf merged commit 788f53b into AY2021S1-CS2103T-F11-1:master Nov 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants