-
Notifications
You must be signed in to change notification settings - Fork 138
Add info messages to inform developers of expected errors #2639
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
Conversation
Actually, another way to allow for errors to users and warnings to developers is to detect Would this solution be better to keep the urgency of errors for users and hide these intended errors from developers during testing?
|
I don't think there's a need to make such fine differentiation between a user and a developer by adjusting the log level. We can certainly improve the logging, but doesn't have to reduce it to a warning. |
Would it be better to instead log it as a success during TEST MODE? So we leave it as an error for both users and developers, but only during a test run do we adjust it to show something like "Success: invalid case of URL in popover element caught". This way, both users and developers will be aware of any issues since its still an error for them but testing will become less misleading. This fix can also be applied to the other error messages in |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2639 +/- ##
==========================================
+ Coverage 52.80% 53.60% +0.79%
==========================================
Files 130 130
Lines 7162 7162
Branches 1503 1594 +91
==========================================
+ Hits 3782 3839 +57
- Misses 3075 3168 +93
+ Partials 305 155 -150 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
I still think this approach is not the appropriate. The log is valid and intentional, it is printed because we intentionally used erroneous syntax. The fact that the log is printed is an assertion that the error is indeed detected. I think a suitable solution to me is to print a notice when the test is executed (NOT the same as updating the production code to behavior differently in test mode). Something along the line of:
probably somewhere near
|
I see, I think this solution should work. I can add something like this before the line you suggested, what do you think? ...
const expectedErrors = ['URLs are not allowed in the \'src\' attribute'];
console.log(`NOTE: The following ${expectedErrors.length} errors are expected to be thrown
during the test run:`);
expectedErrors.forEach((error, index) => {
console.log(`${index + 1}: ${error}`);
});
testSites.forEach((siteName) => {
... An issue I foresee is that the note/warning gets hidden amongst the other messages so developers might not see that message. Would it be better to put it at the end? Let me know what you think, thanks! |
If u put it at the end, what happens when there's a test failure? Will it still be printed? I'm ok as long as the notice is printed, because if I was suspicious of the warning, I would have looked around for any clues, and at the front/back either is fine as long as it's mentioned |
I see, in that case I'll just add it at the beginning since the tests stop after a test failure. |
I looked into For example, in const nodeProcessor = getNewDefaultNodeProcessor();
const loggerErrorSpy = jest.spyOn(logger, 'error').mockImplementation(() => {});
const result = await nodeProcessor.process(indexPath, index);
const expected = [
'<h1 id="index">Index</h1>',
`<div style="color: red"><div style="color: red">${expectedErrorMessage}</div></div>`,
].join('\n');
expect(result).toEqual(expected);
expect(loggerErrorSpy).toHaveBeenCalledWith(new Error(expectedErrorMessage));
loggerErrorSpy.mockRestore();
I think if we do it this way, we not only get to hide the error during testing which avoids confusion for developers but still also assert that the error has been detected and printed properly. If we wish to still log the error to the console like in the CLI's case, we could also just choose to avoid a mock implementation but still check for the error message. What do you think? |
is the error message in #2612 triggered by The cli case invoke the build command via
Don't really get what you mean here. I do wish to still log the error to the console (retain the existing behavior), if we want to add assertions on the statements logged, i think that's a good to have. At the moment in these "integration" tests we are simply comparing the generated content via string compare. |
Ye, after looking into it, this doesn't help with the CLI case.
Ok, I'll add the assertions to the logged statements. |
I've added some originally missing tests for include and popover in I've also updated the error message for empty src attribute for popover to say 'Empty src attribute in popover in: ${context.cwf}' rather than 'Empty src attribute in include in: ${context.cwf}' |
packages/cli/test/functional/test.js
Outdated
|
||
const expectedErrors = ["URLs are not allowed in the 'src' attribute"]; | ||
|
||
logger.info(`The following ${expectedErrors.length} errors are expected to be thrown during the test run:`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we handle the plurality of errors
just to make it nicer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will do!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the code to now consider if the length of the expectedErrors is 1, let me know if any changes need to be made
@AgentHagu thanks for the work done in this PR. I think it contains too many separate tasks and I would request that we split it into 2 or 3 PRs focusing on each item done
|
Ok, will separate it as suggested! |
What is the purpose of this pull request?
Improve user experience
Overview of changes:
Fixes #2612
This PR adds info messages for developers to inform them of the errors they should expect to see during
npm run test
.The PR also improves the error message shown. Previously, it showed something like:

This is very confusing for users, since it exposes the inner call stack of MarkBind and doesn't inform the user of where to look for this issue. The new error message addresses both of these issues:

The PR also adds some missing tests for
includePanelProcessor.ts
Anything you'd like to highlight/discuss:

The developer guide has also been updated to inform developers of these messages and errors
Testing instructions:
npm run build:backend
npm run test
Proposed commit message: (wrap lines at 72 characters)
Add info messages to inform developers of expected errors
Currently, there are some error messages that appear during
npm run test
. These errors are expected to be logged due tonegative test cases involving
includePanelProcessor.test.ts
.These error messages may be confusing to developers, as they may
be unaware that the errors are expected. To fix this, let's add info
messages to inform developers of any expected errors to be seen
during the test run.
Let's also update the error messages to only display the message,
rather than the entire error stack. Let's update the developer guide
to inform current and future developers to look out for these info
messages and to update them whenever they add similar negative
test cases.
Checklist: ☑️
Reviewer checklist:
Indicate the SEMVER impact of the PR:
At the end of the review, please label the PR with the appropriate label:
r.Major
,r.Minor
,r.Patch
.Breaking change release note preparation (if applicable):