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

Error Codes for Various Exceptions #132

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Conversation

shinobu
Copy link
Contributor

@shinobu shinobu commented Nov 1, 2016

This pull request adds error codes for all Exceptions except for NoViableAltException and EarlyExitException as those both are used only in the Sparql Parser (and I doubt messing with it would be a good idea)

I created the following Error Codes:

DEFAULT_ERROR for 0 as 0 is the default output from the getCode() function of Exceptions
and the places where it appears most likely only wanted to use the third optional parameter for creating an Exception.

DATABASE_ERROR and PARSER_ERROR for -1 as all those files used that number as general exception for the class (most likely only to use the third optional parameter as well)

FILTER_ERROR for 1 for the same reason as DATABASE_ERROR and PARSER_ERROR

NO_ERROR for 20 as the Exceptions with this number are ignored

Copy link
Member

@white-gecko white-gecko left a comment

Choose a reason for hiding this comment

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

Commonly used error codes should be defined on Erfurt_Exception and not additionally on the subclasses.
If the error codes are not used resp. there is no check for the error code, just remove it. The only case, where we need unnecessary error codes, as a placeholder as second parameter to provide a third parameter, Erfurt_Exception::DEFAULT_ERROR should be used.

This especially includes:

  • if a non 0 value is set, but never checked, replace it with Erfurt_Exception::DEFAULT_ERROR,
  • if the last parameter of the Exception constructor is 0 resp. Erfurt_Exception::DEFAULT_ERROR, remove it.

@@ -330,7 +345,7 @@ protected function _getNormalizedErrorCode()
return 1000;
}
} else {
return -1;
return Erfurt_Exception::DATABASE_ERROR;
Copy link
Member

Choose a reason for hiding this comment

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

Why do you replace the return value in this case with a constant, but not three lines above?

@shinobu shinobu force-pushed the feature/Error_Codes branch 2 times, most recently from 224a451 to 5a6296d Compare November 4, 2016 21:13
@shinobu
Copy link
Contributor Author

shinobu commented Nov 4, 2016

I have reworked the names
I kept the previous FILTER_ERROR (now NON_FATAL_ERROR) - because OntoWiki could theoretically be checked in the ErrorController.php (it checks for codes above 0 and below 2k and handles them differently)

@@ -13,6 +13,9 @@
*/
class Erfurt_Exception extends Exception {

const DEFAULT_ERROR = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Add documentation for the usage of the error codes.

@@ -13,4 +13,5 @@
*/
class Erfurt_Store_Exception extends Erfurt_Exception
{
const NO_ERROR = 20;
Copy link
Member

Choose a reason for hiding this comment

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

Move all error code definitions to Erfurt_Exception

@@ -896,7 +896,7 @@ public function getStore()
try {
$this->_store->checkSetup();
} catch (Erfurt_Store_Exception $e) {
if ($e->getCode() != 20) {
if ($e->getCode() != Erfurt_Store_Exception::NO_ERROR) {
Copy link
Member

Choose a reason for hiding this comment

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

Rename this exception to actually reflect its role.

@@ -327,10 +342,10 @@ protected function _getNormalizedErrorCode()
switch($this->_dbConn->getConnection()->errno) {
case 1062:
// duplicate entry
return 1000;
return Erfurt_Store_Exception::NO_ERROR;
Copy link
Member

Choose a reason for hiding this comment

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

This is not very clear.

@@ -327,10 +342,10 @@ protected function _getNormalizedErrorCode()
switch($this->_dbConn->getConnection()->errno) {
case 1062:
// duplicate entry
return 1000;
Copy link
Member

Choose a reason for hiding this comment

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

This method should be changed to boolean output.

@@ -296,10 +308,10 @@ protected function _getNormalizedErrorCode()
switch($this->_dbConn->getConnection()->errno) {
case 1062:
// duplicate entry
return 1000;
return Erfurt_Store_Exception::NO_ERROR;
Copy link
Member

Choose a reason for hiding this comment

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

Same as in mysqli adapter.

Remove commented out code and apply coding standards of
Erfurt_Store_Adapter_EfZendDb
…ltException

and EarlyExitException as they are part of the Parser
@shinobu
Copy link
Contributor Author

shinobu commented Nov 12, 2016

done and rebased onto your pull request @white-gecko

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants