Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve consistency of exception message formatting. #3536

Merged
merged 1 commit into from
May 8, 2019

Conversation

jwage
Copy link
Member

@jwage jwage commented Apr 30, 2019

Q A
Type improvement
BC Break no
Fixed issues fixes #3531

Summary

Improve consistency of exception message formatting. See #3531 for details.

TODO

  • Add tests for exceptions that weren't tested.

@jwage jwage added this to the 3.0.0 milestone Apr 30, 2019
@jwage jwage marked this pull request as ready for review April 30, 2019 02:25
@jwage jwage force-pushed the improve-exception-messages branch 2 times, most recently from ed00719 to 012c657 Compare April 30, 2019 02:45
@jwage jwage requested a review from morozov April 30, 2019 03:19
lib/Doctrine/DBAL/DBALException.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Exception/MissingSQLParam.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Id/TableGenerator.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Query/Exception/NonUniqueAlias.php Outdated Show resolved Hide resolved
@morozov
Copy link
Member

morozov commented Apr 30, 2019

@jwage please see the comments above. I haven't reviewed the entire patch yet.

@jwage jwage force-pushed the improve-exception-messages branch from 012c657 to 63f36a2 Compare April 30, 2019 20:23
@jwage jwage force-pushed the improve-exception-messages branch 3 times, most recently from 4c23709 to 6eba870 Compare April 30, 2019 22:17
lib/Doctrine/DBAL/DBALException.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Driver/PDOStatement.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Driver/PDOStatement.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Exception/FormatArray.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Schema/Table.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Schema/UniqueConstraint.php Outdated Show resolved Hide resolved
tests/Doctrine/Tests/DBAL/ConnectionTest.php Show resolved Hide resolved
tests/Doctrine/Tests/DBAL/Functional/PDOStatementTest.php Outdated Show resolved Hide resolved
@jwage jwage force-pushed the improve-exception-messages branch from 6eba870 to 0ac207b Compare April 30, 2019 23:26
@jwage jwage force-pushed the improve-exception-messages branch from 0ac207b to 5ba53f9 Compare May 1, 2019 01:24
lib/Doctrine/DBAL/Exception/MissingArrayParameterType.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Driver/PDOStatement.php Show resolved Hide resolved
lib/Doctrine/DBAL/Driver/PDOStatement.php Show resolved Hide resolved
lib/Doctrine/DBAL/Types/Exception/ValueNotConvertible.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Types/Exception/SerializationFailed.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Exception/FormatVariable.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Exception/FormatVariable.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/DBALException.php Outdated Show resolved Hide resolved
@jwage jwage force-pushed the improve-exception-messages branch 2 times, most recently from 1858e72 to 2bbc38e Compare May 1, 2019 19:39
@@ -48,7 +49,7 @@ public function __construct(array $data)
*/
public function closeCursor() : void
{
unset($this->data);
$this->data = null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was adding tests for ArrayStatement and this seemed wrong since it can result in PHP errors if you call other public methods after closeCursor()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes perfect sense.

@jwage jwage force-pushed the improve-exception-messages branch from 2bbc38e to 623623a Compare May 1, 2019 19:41
}

if (! is_numeric($shard['id']) || $shard['id'] < 1) {
throw new InvalidArgumentException('Shard Id has to be a non-negative number.');
}

if (isset($this->connectionParameters[$shard['id']])) {
throw new InvalidArgumentException('Shard ' . $shard['id'] . ' is duplicated in the configuration.');
throw new InvalidArgumentException(sprintf('Shard "%s" is duplicated in the configuration.', $shard['id']));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is $shard['id'] a string?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's annotated as int|string in most places but looks like it's a numeric string (or an integer):

if (! is_numeric($shard['id']) || $shard['id'] < 1) {
throw new InvalidArgumentException('Shard Id has to be a non-negative number.');
}

Also, the id comes from sys.federation_member_distributions.member_id:

$sql = 'SELECT member_id as id,
distribution_name as distribution_key,
CAST(range_low AS CHAR) AS rangeLow,
CAST(range_high AS CHAR) AS rangeHigh
FROM sys.federation_member_distributions d
INNER JOIN sys.federations f ON f.federation_id = d.federation_id
WHERE f.name = ' . $this->conn->quote($this->federationName);

which according to this article is INT.

These details are mostly for myself, I'll need this info later to finish the work on strict types.

@jwage jwage force-pushed the improve-exception-messages branch 2 times, most recently from 46809de to 13820a6 Compare May 1, 2019 20:23
@morozov
Copy link
Member

morozov commented May 6, 2019

@jwage I rebased develop yesterday to accommodate recent conflicting changes from master. Please rebase.

@jwage jwage force-pushed the improve-exception-messages branch from 3124f44 to 10b09e1 Compare May 7, 2019 01:11
@jwage
Copy link
Member Author

jwage commented May 7, 2019

@morozov Done!

@@ -30,9 +29,9 @@ public static function new($invalidPlatform) : self

return new self(
sprintf(
"Option 'platform' must be an object and subtype of '%s'. Got '%s'",
'Option "platform" must be an object and subtype of %s. Got "%s".',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No quotes around type needed.

@@ -828,7 +829,10 @@ private function convertSingleBooleanValue($value, $callback)
return $callback(true);
}

throw new UnexpectedValueException("Unrecognized boolean literal '${value}'");
throw new UnexpectedValueException(sprintf(
'Unrecognized boolean literal, "%s" given.',
Copy link
Member

@morozov morozov May 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No quotes around type needed. Or… most likely it will be a printable scalar value. Let's leave it without the GetVariableType.

@morozov
Copy link
Member

morozov commented May 7, 2019

@jwage thanks. Could you look at the build failure and the new comments? Looks like we're really close to finishing it.

@jwage jwage force-pushed the improve-exception-messages branch from 10b09e1 to 67ebcf6 Compare May 7, 2019 21:07
@jwage
Copy link
Member Author

jwage commented May 7, 2019

Fixed latest feedback and fixed the tests.

@morozov morozov merged commit c7cb259 into doctrine:develop May 8, 2019
@morozov
Copy link
Member

morozov commented May 8, 2019

Thank you 🚢

@morozov morozov self-assigned this May 8, 2019
@jwage
Copy link
Member Author

jwage commented May 8, 2019

Cool! Thanks!

morozov added a commit that referenced this pull request May 23, 2019
Improve consistency of exception message formatting.
@morozov morozov removed the WIP label May 23, 2019
morozov added a commit to morozov/dbal that referenced this pull request May 31, 2019
Improve consistency of exception message formatting.
morozov added a commit to morozov/dbal that referenced this pull request May 31, 2019
Improve consistency of exception message formatting.
morozov added a commit that referenced this pull request Jun 13, 2019
Improve consistency of exception message formatting.
morozov added a commit that referenced this pull request Jun 27, 2019
Improve consistency of exception message formatting.
morozov added a commit that referenced this pull request Jun 27, 2019
Improve consistency of exception message formatting.
morozov added a commit that referenced this pull request Jun 27, 2019
Improve consistency of exception message formatting.
morozov added a commit to morozov/dbal that referenced this pull request Aug 26, 2019
Improve consistency of exception message formatting.
morozov added a commit to morozov/dbal that referenced this pull request Aug 27, 2019
Improve consistency of exception message formatting.
morozov added a commit that referenced this pull request Nov 2, 2019
Improve consistency of exception message formatting.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants