Just observed that when throwing Exceptions, the step definitions use different syntax. Example:

throw new \Exception(sprintf('No such Drupal string: %s', $name));

throw new \Exception('No submit button at ' . $this->getSession()->getCurrentUrl());

throw new \Exception("Failed to log in as user \"{$this->user->name}\" with role \"{$this->user->role}\".");

throw new \Exception("No link to " . $link . " on " . $this->getSession()->getCurrentUrl());

throw new \Exception("$region region was not found");

Can anyone please suggest which one of the above is the preferable one?

CommentFileSizeAuthor
#3 exception-messages-1838136-1.patch9.09 KBkssundar

Comments

jhedstrom’s picture

I prefer sprintf('No such Drupal string: %s', $name as they tend to be more readable.

eliza411’s picture

I know this question is about the syntax, but on a content level, I'd like to add that I really appreciate inclusion of the current URL wherever it's appropriate.

kssundar’s picture

Status: Active » Needs review
StatusFileSize
new9.09 KB

Attached is the patch that changes all exception messages to sprintf format as in #1

jhedstrom’s picture

Status: Needs review » Fixed

Committed #3 in 56eee8f. Thanks!

Status: Fixed » Closed (fixed)

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

  • Commit 56eee8f on master, 1.0 authored by ksbalajisundar, committed by jhedstrom:
    Issue #1838136 by ksbalajisundar: Consistency in throwing exceptions.
    

  • Commit 56eee8f on master, 1.0, test-symfony authored by ksbalajisundar, committed by jhedstrom:
    Issue #1838136 by ksbalajisundar: Consistency in throwing exceptions.