1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Improve error message when user encounters a table/column schema error

Summary: These are because they forgot to upgrade_schema.php like 99% of the time.

Test Plan: Hit such an error, got a better error message than before.

Reviewers: btrahan, jungejason

Reviewed By: jungejason

CC: aran, epriestley

Differential Revision: https://secure.phabricator.com/D1786
This commit is contained in:
epriestley 2012-03-05 13:17:21 -08:00
parent 1e4e3d1fef
commit 3a251f9b16
5 changed files with 59 additions and 5 deletions

View file

@ -77,6 +77,7 @@ phutil_register_library_map(array(
'AphrontQueryObjectMissingException' => 'storage/exception/objectmissing',
'AphrontQueryParameterException' => 'storage/exception/parameter',
'AphrontQueryRecoverableException' => 'storage/exception/recoverable',
'AphrontQuerySchemaException' => 'storage/exception/schema',
'AphrontRedirectException' => 'aphront/exception/redirect',
'AphrontRedirectResponse' => 'aphront/response/redirect',
'AphrontReloadResponse' => 'aphront/response/reload',
@ -961,6 +962,7 @@ phutil_register_library_map(array(
'AphrontQueryObjectMissingException' => 'AphrontQueryException',
'AphrontQueryParameterException' => 'AphrontQueryException',
'AphrontQueryRecoverableException' => 'AphrontQueryException',
'AphrontQuerySchemaException' => 'AphrontQueryException',
'AphrontRedirectException' => 'AphrontException',
'AphrontRedirectResponse' => 'AphrontResponse',
'AphrontReloadResponse' => 'AphrontRedirectResponse',

View file

@ -293,27 +293,32 @@ class AphrontMySQLDatabaseConnection extends AphrontDatabaseConnection {
$error = mysql_error($connection);
}
$exmsg = "#{$errno}: {$error}";
switch ($errno) {
case 2013: // Connection Dropped
case 2006: // Gone Away
throw new AphrontQueryConnectionLostException("#{$errno}: {$error}");
throw new AphrontQueryConnectionLostException($exmsg);
case 1213: // Deadlock
case 1205: // Lock wait timeout exceeded
throw new AphrontQueryRecoverableException("#{$errno}: {$error}");
throw new AphrontQueryRecoverableException($exmsg);
case 1062: // Duplicate Key
// NOTE: In some versions of MySQL we get a key name back here, but
// older versions just give us a key index ("key 2") so it's not
// portable to parse the key out of the error and attach it to the
// exception.
throw new AphrontQueryDuplicateKeyException("{$errno}: {$error}");
throw new AphrontQueryDuplicateKeyException($exmsg);
case 1044: // Access denied to database
case 1045: // Access denied (auth)
case 1142: // Access denied to table
case 1143: // Access denied to column
throw new AphrontQueryAccessDeniedException("#{$errno}: {$error}");
throw new AphrontQueryAccessDeniedException($exmsg);
case 1146: // No such table
case 1154: // Unknown column "..." in field list
throw new AphrontQuerySchemaException($exmsg);
default:
// TODO: 1064 is syntax error, and quite terrible in production.
throw new AphrontQueryException("#{$errno}: {$error}");
throw new AphrontQueryException($exmsg);
}
}

View file

@ -15,6 +15,7 @@ phutil_require_module('phabricator', 'storage/exception/connection');
phutil_require_module('phabricator', 'storage/exception/connectionlost');
phutil_require_module('phabricator', 'storage/exception/duplicatekey');
phutil_require_module('phabricator', 'storage/exception/recoverable');
phutil_require_module('phabricator', 'storage/exception/schema');
phutil_require_module('phutil', 'error');
phutil_require_module('phutil', 'serviceprofiler');

View file

@ -0,0 +1,34 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @group storage
*/
final class AphrontQuerySchemaException extends AphrontQueryException {
public function __construct($message) {
$message .=
"\n\n".
"NOTE: This usually indicates that the MySQL schema has not been ".
"properly upgraded. Run scripts/sql/upgrade_schema.php to ensure your ".
"schema is up to date.";
parent::__construct($message);
}
}

View file

@ -0,0 +1,12 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'storage/exception/base');
phutil_require_source('AphrontQuerySchemaException.php');