ElkArte Community

Elk Development => Feature Discussion => Topic started by: Burke Knight on February 20, 2016, 08:40:27 am

Title: Errors....
Post by: Burke Knight on February 20, 2016, 08:40:27 am
I think it would be nice, on errors, like connection to databases, if they were a bit more styled, and maybe include a better message to the users, like the maintenance mode does.

Now, since it would not be able to get the message from database, would have to have it in a language file.
Besides the error, maybe a message to the users, that tells them the site will be back as soon as maintenance is done, but be more than the standard message, which IMHO, is a bit bland.

QuoteSorry, ElkArte was unable to connect to the database. This may be caused by the server being busy. Please try again later.

Attention members, we are attempting to restore the site to normal operations...news will be posted once we are back!

Sure would look better than just:

QuoteSorry, ElkArte was unable to connect to the database. This may be caused by the server being busy. Please try again later.
Title: Re: Errors....
Post by: Flavio93Zena on February 20, 2016, 08:47:45 am
And this, thanks to a problem on my site <_< Lol ;D
Title: Re: Errors....
Post by: emanuele on February 20, 2016, 08:58:35 am
If we want to nitpick, a "Attention members, we are attempting" has the meaning "we (site OP) are doing something", but in fact it may just be nobody is doing anything because they do not know (been there done that).
So I'd better prefer a less professional "please inform the administrator at {email-address-or-something}" rather than a encouraging, but potentially false message.

Also, about the styling, the tricky part is that the "current" theme is defined in the database, so in order to style the page Elk needs a database connection[1], but not having it the only possible thing, is a) use the default theme, and 2) hope the themes are in the same directory as index.php[2], that is true in likely 99.9% of the cases, maybe more, but nonetheless something to take in consideration.
technically it would be the same for the language, even though I guess we do our good share of guessing where the language actually is, so it should be less of a problem, but I'm not entirely sure.
Just for the record, this may or may not be true depending on the setup.
Title: Re: Errors....
Post by: Burke Knight on February 20, 2016, 12:14:06 pm
Hmmm... Good idea on the contact.  Would there be a way, to set that as a field, in the General Settings?
Where the Admin can put an email address or a URL to some other form of contact?
Title: Re: Errors....
Post by: emanuele on February 20, 2016, 04:07:37 pm
What would be the point of yet-another-setting when Elk cannot read the database?
Yet another email address in Settings.php then?
I would just go with the one notified, at best, let the admin specify more than one, that could be potentially useful.
Title: Re: Errors....
Post by: ahrasis on February 21, 2016, 04:29:48 am
Do you mean you want to be notified if your forum database is inaccessible? Or simply beautify its language on that error? Of course language can be changed to suit your needs, if that is necessary to you.
Title: Re: Errors....
Post by: Flavio93Zena on February 21, 2016, 11:58:28 am
I am not sure it has anything to deal with that, at all... We are talking about the error page being ugly, it's up to individual admins to set up a contact page or not, not everyone wants it.
Title: Re: Errors....
Post by: Burke Knight on February 21, 2016, 12:08:51 pm
Not only that, but would have to have a link on the error page, for an alternative contact way, if the forum is not available.
Contact form on forum, would not work, but link to a contact form on another site, would.

For example, on my forum's error page, I could link to my support system, or regular site's contact form. Or both...LOL
Title: Re: Errors....
Post by: Flavio93Zena on February 21, 2016, 01:58:23 pm
You can just throw an <a href> into the error string, works, I am unsure what to suggest here in general.
Title: Re: Errors....
Post by: Flavio93Zena on February 22, 2016, 02:50:58 am
Thing is, as mentioned before, it would need to be coded manually, and since you can't call anything from db, you will have just a default theme.
Title: Re: Errors....
Post by: Antechinus on February 22, 2016, 03:40:51 am
Well you can always customise it so it suits your site even when the db is down. Done that before. Obviously it's site-specific though, so not a one size fits all solution.

(Basically, use static HTML page that calls your site theme's CSS files, and has whatever message you like hard-coded into the HTML)
Title: Re: Errors....
Post by: Flavio93Zena on February 22, 2016, 11:40:08 am
Yeah, but for you, me and pretty much the ""elite"" users, it can be fine, but it will create some kind of "wut" effect otherwise :P
Title: Re: Errors....
Post by: Antechinus on February 22, 2016, 12:58:09 pm
Yeah but it's really cool, because you can have it with bouncing parrots. :D

Ok, seriously, just thinking aloud here: you could set it up so that you have a base template (static HTML) that was written to from an admin interface. So all you would have to do is set a path to the CSS files and add your custom message.

IOW, similar to the way hosting panels can usually set up custom 404 pages, etc.
Title: Re: Errors....
Post by: Flavio93Zena on February 22, 2016, 05:03:47 pm
And then I wonder... Does it really worth it to go through so much of an hassle just for an error page that will hopefully be displayed the fewer the better?
Title: Re: Errors....
Post by: ahrasis on February 22, 2016, 07:10:36 pm
I'll just stick to default as that is not really a necessary enhancement.
Title: Re: Errors....
Post by: Burke Knight on February 22, 2016, 07:15:57 pm
I'd like to see maybe a place in General Settings, where the admin can insert an email address, or a URL, to be pasted onto the error pages, as a "Contact us if you see this page" kind of thing.

Should work, as I know some fields do not get added to the database.
Like template edit settings.
Title: Re: Errors....
Post by: ahrasis on February 22, 2016, 09:05:47 pm
Here, I think, an email is already set to be sent on this error.
Code: [Select]
// Language files aren't loaded yet :(.
 $db_error = $db->last_error($db->connection());
 @mail($webmaster_email, $mbname . ': Database Error!', 'There has been a problem with the database!' . ($db_error == '' ? '' : "\n" . $db->db_title() . ' reported:' . "\n" . $db_error) . "\n\n" . 'This is a notice email to let you know that the system could not connect to the database, contact your host if this continues.');
 }

But if you really really want to do it, as addon or modifications, find this code in Errors.php under display_db_error.
Code: [Select]
echo '<!DOCTYPE html>
<html>
 <head>
 <meta name="robots" content="noindex" />
 <title>Connection Problems</title>
 </head>
 <body>
 <h3>Connection Problems</h3>
 Sorry, we were unable to connect to the database.  This may be caused by the server being busy.  Please try again later.
 </body>
</html>';
Then replace its place with this:
Code: [Select]
	require_once(__DIR__ . '/../themes/default/Errors.template.php');
template_display_db_error();

Move the above echoed html code (or customized it) into Errors.template.php in default themes folder under a (newly created) function template_display_db_error. You may later call the said from admin page to edit or change it accordingly.

Edited: Simplified.
Title: Re: Errors....
Post by: emanuele on February 23, 2016, 03:09:05 am
Template settings are saved in the database.
The only settings not saved in the database are those is the Settings.php file.
Title: Re: Errors....
Post by: Antechinus on February 23, 2016, 04:06:03 am
Quote from: Flavio93Zena (#OpIsis) – And then I wonder... Does it really worth it to go through so much of an hassle just for an error page that will hopefully be displayed the fewer the better?
Probably not, or at least not for core. Easy to do as a mod if anyone wants to do it. Easy to do manually on a per-site basis if anyone wants to do that (I've done it before). But probably not worth adding more stuff to the core build. I just mentioned a way of doing it without too much drama because somebody asked.
Title: Re: Errors....
Post by: Burke Knight on February 23, 2016, 04:39:24 am
Quote from: emanuele –
Quote from: Burke Knight – Like template edit settings.
Template settings are saved in the database.
The only settings not saved in the database are those is the Settings.php file.


Template edits like in non-hook mods?
Never knew that, as never had database calls in most of my SMF mods.
Title: Re: Errors....
Post by: emanuele on February 23, 2016, 07:22:33 am
Settings are not edits. :P
I guess you lost me somewhere, oh well.
Title: Re: Errors....
Post by: ahrasis on February 23, 2016, 08:20:14 am
I think he means the page where admin can modify any theme template file (which we already have).

The idea could be, create a file for it in default theme folder, move the html page code in Errors.php to that file, include / display the page on database connection error, the file can be modify via the above said page.

Does it make sense?
Title: Re: Errors....
Post by: emanuele on February 23, 2016, 08:58:40 am
Ok, let me try to explain it another way so that it may be becomes a little more clear:
0) all the data related to the theme (paths, urls, settings) are stored in the database,
1) we are talking about the case Elk is not able to connect to the database,
2) if Elk cannot connect to the db it cannot (reliably) know where the theme is (because this data is stored in the database, see point 0),
3) if Elk cannot (reliably) know where the theme is, it cannot load a theme file.

From that we find out that:
1) the html is in Errors.php because in that case Elk cannot be sure where the files are (please, remember Elk allows to store themes in arbitrary directories),
2) we cannot more the HTML code to a template file because in case of database error we are not sure where the themes directory is (the paths are stored in the database!).

There is a possible mid/long term solution to this, but I don't want to mention it here and now because I know it will derail the topic even more, so let's do what we can with what we have.
We know in most of the cases the default theme is under forum/themes/default, so (as I said two days ago) Elk can probe and see if the theme is actually there, if it is there, it can try to use it (because the theme may be in the expected place, but assets may be served from another url nothing is completely sure in this case), otherwise dull empty screen.

At the moment, this is the only possible workaround.

About additional links/emails/whatever, if I'm not wrong, in case of database errors Elk already sends out an email to the "forum email" (the one set in server config IIRC), what is possible is to let admins specify multiple email addresses there. Anything more would require more settings stored in Settings.php (that is something I would avoid if at all possible) or a working database connection (that in the case at hands we don't have).
Title: Re: Errors....
Post by: ahrasis on February 23, 2016, 10:43:27 am
Edited: It seems using the DIR . '../themes/default/ is better than $_SERVER['DOCUMENT_ROOT'] . '/themes/default/ since ElkArte forum might not be in the root folder. Please refer to edited Reply #18 (http://www.elkarte.net/community/index.php?topic=3317.msg23633#msg23633).