Skip to content

Conversation

@mdperez86
Copy link
Contributor

@mdperez86 mdperez86 commented Oct 18, 2022

All Submissions:

Changes proposed in this Pull Request:

Closes #35037.

How to test the changes in this Pull Request:

  1. Go to Add new product page
  2. If you add a new shipping class you should see a placeholder: e.g. Fragile products in the name field of the Shipping Class dialog
  3. Add a category to the product and then publish it.
  4. When editing that product and try to add a new shipping class the first time in the shipping class name and slug fields of the Shipping Class dialog should be filled with the name and slug of the first product category.
  5. If you added that new shipping class with the prefilled category data and try to add a new shipping class again then no prefilled name and slug should happend anymore per product edition.

Screen.Recording.2022-10-19.at.10.03.13.AM.mov

  1. If you try to add a new shipping class with any of the previous added slugs you should see a snackbar error with this message: We couldn’t add this shipping class. Try again in a few seconds.

Screen.Recording.2022-10-19.at.10.27.17.AM.mov

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you created a changelog file for each project being changed, ie pnpm --filter=<project> run changelog add?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@mdperez86 mdperez86 added the Product/Inventory Management Issues related to product or product page. label Oct 18, 2022
@mdperez86 mdperez86 requested a review from a team October 18, 2022 21:16
@mdperez86 mdperez86 self-assigned this Oct 18, 2022
@github-actions github-actions bot added focus: react admin plugin: woocommerce Issues related to the WooCommerce Core plugin. labels Oct 18, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 18, 2022

Test Results Summary

Commit SHA: 06a8058

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests20000202021m 2s
E2E Tests186006019216m 9s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@mdperez86 mdperez86 force-pushed the add/35037-error-handling branch 2 times, most recently from fbaf275 to 693b282 Compare October 19, 2022 12:59
@mdperez86 mdperez86 marked this pull request as ready for review October 19, 2022 13:33
Copy link
Contributor

@joshuatf joshuatf left a comment

Choose a reason for hiding this comment

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

Awesome work, @mdperez86!

Testing well on my end, just left a question on the error message we show.

Also curious if this was intentional. "Add new shipping class" is shown as the 2nd item in the list. I kind of expected it to show at the end, but that may not be a good expectation. cc @jarekmorawski

.catch( ( error: Error ) => {
createErrorNotice(
__(
'We couldn’t add this shipping class. Try again in a few seconds.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use the error returned from the response? I think this error commonly might be a duplicate slug, which would be good for merchants to know since it won't resolve itself after a few seconds.

The response is pretty generic and not pretty:

A term with the name provided already exists in this taxonomy

But I think this might still be more useful for merchants to know. cc @jarekmorawski

Copy link
Contributor Author

@mdperez86 mdperez86 Oct 20, 2022

Choose a reason for hiding this comment

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

There are a lot of reasons why I prefer not to show any server error to the final user:

  1. Translation
  2. Politeness
  3. Wrong error handling. What about 500 Internal Server Error or 503 Service Unavailable.
  4. Formatting

Also consider that we are not filtering any kind of error given its status code or anything else. So if we show the server error that will mean: show any server error that may occur no matter the reason and the message.
In order to be more specific with the error messages we will need better server responses with particalar kind of error codes that let the frontend understand what should be the right final message to show.

Choose a reason for hiding this comment

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

But I think this might still be more useful for merchants to know. cc @jarekmorawski

I agree, but I thought we can't tell what the error is about? 🤔 If we can, it'd make sense to surface it directly within the form, but having spoken with Maikel earlier, we've decided to go with a generic error message. Let me know if there's any wiggle room there. The more specific the error message, the better. 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

@mdperez86 Those are good concerns. We can probably not worry too much about a couple of them:

Translation

The errors are translated. And because they've been around for a while, are actually more likely new to be translated than our newer frontend strings.

Politeness

While A term with the name provided already exists in this taxonomy does not match the tone of our entire application, this is a common problem throughout Woo right now.

I don't think this message is impolite. It's certainly going to make the user happier knowing how they can solve the issue rather than trying again every few seconds.

Wrong error handling. What about 500 Internal Server Error or 503 Service Unavailable.

Great point. Generally 5xx errors are good candidates for catch-all error messages. 4xx errors like this one should have some information that could prove useful to help the user immediately correct the issue.

If nothing else, more specific error messages help us with debugging down the road.

Formatting

This is a real possibility. Luckily most of the error messages are simply strings, but I've seen some that include links or other small bits of HTML.

In a follow-up, it might be worth us allowing some of this inside the toast notices. We have some sanitization tools that might make this relatively trivial to do.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, but I thought we can't tell what the error is about? 🤔 If we can, it'd make sense to surface it directly within the form

@jarekmorawski we probably can catch this before it's sent to the server, but it does not look like that validation is in place yet.

but having spoken with Maikel earlier, we've decided to go with a generic error message. Let me know if there's any wiggle room there.

I'd really recommend not using a generic error message when we have useful information at our disposal that could immediately help a user solve the issue they're facing. I'd rather display a somewhat poorly formatted error message that would help a user than a pretty one that leaves them confused.

Front-end validation is a good first step in catching issues, but can't and shouldn't be relied on fully. Essentially in this order we should:

  1. Front-end validation catches the error before we send it to the server.
  2. If the front-end validation fails, display helpful error messages from the server.
  3. If the error is a server error that's not helpful with a 5xx code, display a generic error message.

Optionally, at step 2 above, we could write custom error messages for each status type, but this is obviously a lot more work than returning better error messages from the server.

Choose a reason for hiding this comment

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

Sounds perfect. I'm happy to write these messages if you can list all possible combinations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

4xx errors like this one should have some information that could prove useful to help the user immediately correct the issue.

Agree, but this phrase A term with the name provided already exists in this taxonomy say nothing to me. To have a good error handling the server should responds with or similar:

{
  "code": 400,
  "errors": [
    { "code": "UNIQUE_SERVER_ERROR_ID", "field": "slug", "message": "Already exists" },
    { "code": "OTHER_UNIQUE_SERVER_ERROR_ID", "field": "name", "message": "Required field" },
  ]
}

Or in case the error is not related to any field in particular

{
  "code": 400,
  "errors": [
    { "code": "UNIQUE_SERVER_ERROR_ID", "message": "A business rule has been violated" },
  ]
}
{
  "code": 500,
  "errors": [
    { "code": "UNIQUE_SERVER_ERROR_ID", "message": "Internal Server Error" },
  ]
}

Server messages should be used for debuging porpose unless a server behaves as a Backend For Frontend (BFF).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another thing here to remember: we are just working on a MVP. And this a design discussion we should have as a team because whatever be the final point here it should be implemented for the rest of the project. @joshuatf it would be awesome if you lead this discussion with all the team sync or async in order the let them participate in the conversition and in the final decision. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, but this phrase A term with the name provided already exists in this taxonomy say nothing to me.

I disagree pretty strongly with this. A term with the name provided already exists in this taxonomy is far more suggestive as to what the error is than We couldn’t add this shipping class. Try again in a few seconds.

Ultimately, we should strive for good user experience. Telling users indefinitely to "Try again in a few seconds" when the issue will not self-resolve is misleading and bad UX.

Server messages should be used for debuging porpose unless a server behaves as a Backend For Frontend (BFF).

Assuming you're just talking about the messages, I agree with this sentiment. But we have codes that can inform the presentation layer what message to add.

Another thing here to remember: we are just working on a MVP. And this a design discussion we should have as a team because whatever be the final point here it should be implemented for the rest of the project.

I'm happy to have this discussion as a team, but I'm not quite sure what the discussion we're having is. We have a fairly easy to hit error and the error message does not tell the user what the error is. If the options are:

a. Catch the fixable error, but give a misleading message to a user
b. Catch the fixable error, tell the user how to fix it

This seems like a no-brainer. I think the amount of time we've spent discussing this could have gone towards adding a few lines to add this error message in.

useDispatch: jest.fn(),
} ) );

function getShippingClassDialog() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Love these helper functions!

@jarekmorawski
Copy link

Also curious if this was intentional. "Add new shipping class" is shown as the 2nd item in the list. I kind of expected it to show at the end, but that may not be a good expectation. cc @jarekmorawski

@joshuatf The idea is the last place in the list is reserved for the Add new option because 1) it's easy to keep it that way as the list grows 2) that's where such options are usually located and users are used to it.

@mdperez86 mdperez86 requested a review from joshuatf October 20, 2022 18:45
@mdperez86 mdperez86 force-pushed the add/35037-error-handling branch from d85e2e1 to c6ad9b8 Compare October 21, 2022 14:55
Copy link
Contributor

@joshuatf joshuatf left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, Maikel! This looks good and error catching is working well for me.

We'll discuss how we want to elegantly handle similar or common errors going forward via p2, but this looks like a good solution for the mvp. 🚢

@mdperez86 mdperez86 merged commit 64ee20f into trunk Oct 22, 2022
@mdperez86 mdperez86 deleted the add/35037-error-handling branch October 22, 2022 13:47
@github-actions github-actions bot added this to the 7.2.0 milestone Oct 22, 2022
@github-actions
Copy link
Contributor

Hi @mdperez86, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:

  • Add the release: add testing instructions label

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin. Product/Inventory Management Issues related to product or product page.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Shipping] Shipping class creation error handling

4 participants