Cms: [FR] Have Craft be smarter about db connection (and other setup) issues

Created on 25 Aug 2020  Ā·  10Comments  Ā·  Source: craftcms/cms

It'd be nice if Craft did the equivalent of spell check or Google in suggesting what people might have _intended_ when setting up a new Craft project.

I've spent more time than I'd care to admit debugging db connection issues... so what if, for example, instead of just saying:

"Craft isn't installed yet"

…it would try connecting without the DB_TABLE_PREFIX or try connecting _with_ craft_ or other common DB_TABLE_PREFIX settings just to see if maybe it could be more helpful in diagnosing what's wrong?

This is just one example; but there are many common errors that Craft could probably check for pretty easily (and the support folks at P&T should be intimately familiar with).

This is a really neat thing I see in Rust, for example, where if you make a mistake, they guess at common errors that people make (and more often than not, they are right). For example:

https://www.reddit.com/r/rust/comments/acapjb/rust_error_messages_are_so_quite_3/

I think Craft's CLI and CP setup wizard could be made significantly more friendly, and reduce support, if common setup errors are checked for.

ref: https://twitter.com/nystudio107/status/1298342662500757506?s=20

enhancement site development

Most helpful comment

We do a bit of this – auto-testing 127.0.0.1 if the server is set to localhost for example, from the setup command. And Yii already has similar command name suggestions built in:

$ php craft hlp
Unknown command: hlp

Did you mean one of these?
    - help
    - gc

I’ve just replaced the Craft isn’t installed yet! warning with the following, depending on the circumstance:

  • No DB connection: Craft can’t connect to the database. Check your connection settings.
  • Error querying the info table row: Craft can’t fetch the `[info table]` table row. Exception: [exception message]
  • Unknown issue querying the info table row: Craft can’t fetch the `[info table]` table row.

The info table name will include the configured DB table prefix, as will the exception message if there is one, so that should help point you in the right direction if that’s the culprit. Example:

Craft can’t fetch the `craft_info` table row.                                                           
Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'craft3.craft_info' doesn't exist

All 10 comments

I love it. There are so many times when we spin our wheels over stupid stuff (like the craft_ prefix vs non-prefix), it would be great if some of that could be ironed out. I'm not sure what all of the nuances are, but there are definitely minor issues that Craft could troubleshoot more automatically.

Even spitting out basic footnote along the lines of "Not expecting to see the installer? You may be seeing this because your database couldn't be found: check your configuration." would be helpful. You could potentially echo out the current config settings too - though that may be a security issue.

I would rather it tell me though, than guess at the right settings if my current settings are wrong. I'm not for magic fixes as that could lead to unexpected things - for example it "correctly guessing" and connecting to a database on staging when you _thought_ you were on local - which then allows you to make changes in the wrong environment, etc. No - just give me a heads up and a pointer to what might be wrong.

Right @MattWilcox it wouldn't magically fix anything... but it could offer magical suggestions to help _you_ figure out what's wrong.

Exactly, you just want the system to be your "rubber duck". You don't want it to actually _do_ anything for you.

_"Craft isn't installed yet"_ doesn't get you very far on its own... Craft can do better. šŸ˜‰

Empathetic Errors!

(EE for short)

Yes, please improve this.

We do a bit of this – auto-testing 127.0.0.1 if the server is set to localhost for example, from the setup command. And Yii already has similar command name suggestions built in:

$ php craft hlp
Unknown command: hlp

Did you mean one of these?
    - help
    - gc

I’ve just replaced the Craft isn’t installed yet! warning with the following, depending on the circumstance:

  • No DB connection: Craft can’t connect to the database. Check your connection settings.
  • Error querying the info table row: Craft can’t fetch the `[info table]` table row. Exception: [exception message]
  • Unknown issue querying the info table row: Craft can’t fetch the `[info table]` table row.

The info table name will include the configured DB table prefix, as will the exception message if there is one, so that should help point you in the right direction if that’s the culprit. Example:

Craft can’t fetch the `craft_info` table row.                                                           
Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'craft3.craft_info' doesn't exist

Craft 3.5.7 is out now with this change.

I was hoping for something a bit more all-encompassing (at least as an open FR) akin to Laravel Ignition:

https://flareapp.io/ignition

Tho it looks like @michaelrog may be carrying this torch: https://twitter.com/michaelrog/status/1301176187218259970

Need separate GH issues for separate feature requests. We can’t really act on ā€œplease make it better in all the waysā€ šŸ™ƒ

Was this page helpful?
0 / 5 - 0 ratings

Related issues

darylknight picture darylknight  Ā·  3Comments

lukebailey picture lukebailey  Ā·  3Comments

michel-o picture michel-o  Ā·  3Comments

bitboxfw picture bitboxfw  Ā·  3Comments

rynpsc picture rynpsc  Ā·  3Comments