Problem/Motivation
The pre-installed view "Archive" will crash to a white screen with the text "The website encountered an unexpected error. Please try again later." if an invalid date is entered in the URL as the context filter.
The "Created Year + Month" context filter wants the format to be YYYYMM. Anything that strays from this format results in white screen of death.
My expected behavior for an invalid date would either a "No results" page, "summary page" or a "Page not found" error. The white screen is a terrible user experience and strikes me as being a bug.
Steps to reproduce
1. Clean install of Drupal 8.8.1
2. Enable "Archive" view
3. Enter any of the following paths "/archive/202013" or "/archive/20191201" or "/archive/foo"
Proposed resolution
BEFORE

AFTER

Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #40 | After patch.png | 256.04 KB | nikhilraut |
| #40 | Before patch.png | 44.82 KB | nikhilraut |
| #34 | interdiff_25-31.txt | 458 bytes | vitorbs |
| #33 | 3107284-31.patch | 618 bytes | vitorbs |
| #32 | after.png | 55.75 KB | vitorbs |
Comments
Comment #2
robert gomez commentedComment #3
avpadernoComment #7
larowlanThe view should have argument validation added
Comment #9
anjali rathodUnable to reproduce the error.
Comment #10
avpadernoComment #11
anjali rathodComment #12
jobsons commentedI'll work on it.
Comment #13
jobsons commentedUnassigning the task
Comment #14
diegorsI'll look into that.
Comment #15
diegorsI found the bug and created the patch to fix it.
Now returns a 404 page.
Comment #16
diegorsI just realize that I made a mistake, I will keep working on the bug.
Comment #17
Munavijayalakshmi commentedRectified the following errors,
217 | ERROR | [x] Trailing punctuation for @see references is not
| | allowed.
283 | ERROR | [x] Trailing punctuation for @see references is not
| | allowed.
Comment #18
Munavijayalakshmi commentedComment #20
diegorsComment #21
diegorsAfter tests, I realized that the error happens in file core/modules/views/src/Plugin/views/argument/YearMonthDate.php in title() function:
When the title receives a value that is not a valid date, this patch fixes it, but I am not sure if is the correct way.
The previous patch should be removed.
Comment #22
gquisini commentedI'll be reviewing.
Comment #23
gquisini commentedSo, #21 patch worked, no more "white screen of death". I just changed the message to something more understandable.
Comment #24
lucasscComment #25
lucasscHi!
I applied patch in #23 for 9.5.x-dev and works fine, instead of the "white screen of death" I saw a much more elegant "No results" page.
I'm attaching a suggestion to improve code readability. Please, review this.
Comment #26
lucasscComment #27
gquisini commentedI'll be doing the review.
Comment #28
gquisini commentedEverything is working and now the code is easier to understand.
Comment #29
quietone commentedWould be nice to have this fixed, thanks for getting this closer to commit.
This is changing the user insterface, adding usability tag. The display message needs to be reviewed and the text agreed to.
A before and after screenshot would be helpful, both in the Issue summary, not a comment. The before one should be /archive, not the error message.
There are several steps, or gates, that an issue must pass before it is marked RTBC. For most issues following step 10 in the Review a patch or merge request task of the Contributor guide is sufficient. The complete list of core gates has more topics.
Comment #30
vitorbs commentedI'll work on this one.
Comment #31
vitorbs commentedI applied the patch #25 and works fine, the whit screen error is not appearing anymore as you can see on the screenshots above.
And i also changed the error message to "No records found", what do you think?
Comment #32
vitorbs commentedComment #33
vitorbs commentedComment #34
vitorbs commentedComment #35
vitorbs commentedComment #36
vitorbs commentedI added the after and before screenshots in the issue summary.
Comment #37
sophiavs commentedI'll do the review
Comment #38
sophiavs commentedI tested the last patch and it stopped the error message to show when trying to access a archive view that doesn't exist. Testing with other view it didn't cause any bug.
I think the message "No records found" is good and simple to understand.
Comment #39
nikhilraut commentedComment #40
nikhilraut commentedAfter applying the patch #31 now showing message "No records found"
Comment #41
lendudeShouldn't this error message be translatable? But, as also pointed out in #21, I'm not sure this is the right solution. Shouldn't we fix the root cause of this and fix the offending title() method?
Also, this needs a test.
Comment #42
lucasscMaybe we can validate the date format before using
strtotimeinside thetitle()method?We could use a regex like
/^[0-9]{4}(0[1-9]|1[0-2])$/, it would returns true for '202209' and false for '20191201', '202013' or 'foo'.Comment #43
avpadernoI am wondering: Does that happens only with the Archive view, or does it happen with all the views using that argument handler (which should not accepts values like foobar)?
In the first case, we should check what causes this issue with the Archive view. In the latter case, it's clearly the argument handler that needs to be fixed.
In both the cases, validating the value in
title()would be too late, and it won't fix other issues.Comment #44
avpadernoI take that the argument handler for the Archive view is the
YearMonthDateclass, which uses the following code inYearMonthDate::title().Effectively, that code expects
$this->argumentto contain the correct value, but it's not its task to check the received argument is valid, since argument handlers have avalidateArgument().This is the code used by
ArgumentPluginBase::validateArgument().None of the argument plugins extends that method.
Either the argument_validator plugin set for the date_year_month argument handler is wrong or it is too permissive on the allowed values.
Comment #45
avpadernoThe issue summary needs to be updated, since it doesn't show the effective error that is causing the WSOD.
I thought it would be
strtotime()that throws an exception or a warning when it receives a wrong argument, but that doesn't happen withecho strtotime("foobar15 00:00:00 UTC");.The output is only different for PHP 4.3.0-4.3.11, 4.4.0-4.4.9, and 5.0.0-5.0.5, which show
-1instead of an empty string.