See #2514044: Do not use SafeMarkup::format in exceptions and the codings standards for exceptions: it seems we've been creating exceptions the wrong way for the past few months, they should now just be plain strings.
Which makes sense, I guess – with Twig autoescaping there is little use for having a markup object there (unless you want HTML in the exception message, but we don't, and it sounds like a bad idea anyways).

So, the task here is simple, if strenuous: search through all cases where we create exceptions and replace any formatting in there with just a plain string (double quotes preferred, otherwise concatenation – please no sprintf()).

Comments

drunken monkey created an issue. See original summary.

borisson_’s picture

Issue tags: +Novice

I tagged the same issue for facets as novice, doing the same here.

vinay15’s picture

Assigned: Unassigned » vinay15
vinay15’s picture

Assigned: vinay15 » Unassigned
joshi.rohit100’s picture

Assigned: Unassigned » joshi.rohit100
joshi.rohit100’s picture

Assigned: joshi.rohit100 » Unassigned
sagar ramgade’s picture

Status: Active » Needs review
StatusFileSize
new14.98 KB

The patch attached removes FormattableMarkup from exceptions, add string within single quotes and concatenates them.

Status: Needs review » Needs work

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new14.05 KB
new15.71 KB

Fixed test + use double quotes as suggested in the IS.

Status: Needs review » Needs work

The last submitted patch, 10: do_not_use-2728399-10.patch, failed testing.

The last submitted patch, 10: do_not_use-2728399-10.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new892 bytes
new15.71 KB
drunken monkey’s picture

Status: Needs review » Needs work

Thanks for taking this on, nice work!

However, I spotted several small mistakes:

  1. +++ b/search_api_db/src/DatabaseCompatibility/MySql.php
    @@ -24,11 +24,7 @@ class MySql extends GenericDatabase {
    +      throw new SearchApiException(get_class($e) . " while trying to change collation of {$type} search data table {$table} ':' {$e->getMessage()}", 0, $e);
    

    I'm pretty sure the ':' part there is wrong.

  2. +++ b/src/Entity/Index.php
    @@ -875,7 +863,7 @@ class Index extends ConfigEntityBase implements IndexInterface {
    +      throw new SearchApiException("Couldn't index values on index {$this->label()}' (index is disabled)");
    

    Superfluous apostrophe.

  3. +++ b/src/Entity/Server.php
    @@ -132,9 +132,7 @@ class Server extends ConfigEntityBase implements ServerInterface {
    +        throw new SearchApiException("The backend with ID '{$this->getBackendId()}' could not be retrieved for server '{$this->label()}.");
    

    Missing second single quote for server label.

Also, that's just my opinion, but

  1. I prefer to use the curly braces around variables only when necessary. Syntax highlighting makes it clear enough, in my opinion, what the variables are.
  2. I just learned for the first time you can even do method calls inside strings, so I'd personally call this pretty confusing. I'd prefer assigning these return values to variables beforehand and then including those instead.

I'm prepared to be overvoted on both of those, though. (For the former, though, it's also a problem of consistency, since we're not doing that anywhere else in the module. (For the latter, too, really, but not so much of an argument there, I'd say.))

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new19.44 KB
new22.02 KB

So, something like this?

drunken monkey’s picture

StatusFileSize
new15.53 KB
new22.2 KB

Yes, better, thanks!
However, let's be consistent with using single quotes around variables, and variable substitution instead of concatenation. Patch attached.
With this, and if those changes look fine to you (and the test bot), too, this would be RTBC for me.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Great, thanks for reviewing!
Committed.
Thanks again, both of you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.