mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-02 19:01:03 +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:
parent
1e4e3d1fef
commit
3a251f9b16
5 changed files with 59 additions and 5 deletions
|
@ -77,6 +77,7 @@ phutil_register_library_map(array(
|
||||||
'AphrontQueryObjectMissingException' => 'storage/exception/objectmissing',
|
'AphrontQueryObjectMissingException' => 'storage/exception/objectmissing',
|
||||||
'AphrontQueryParameterException' => 'storage/exception/parameter',
|
'AphrontQueryParameterException' => 'storage/exception/parameter',
|
||||||
'AphrontQueryRecoverableException' => 'storage/exception/recoverable',
|
'AphrontQueryRecoverableException' => 'storage/exception/recoverable',
|
||||||
|
'AphrontQuerySchemaException' => 'storage/exception/schema',
|
||||||
'AphrontRedirectException' => 'aphront/exception/redirect',
|
'AphrontRedirectException' => 'aphront/exception/redirect',
|
||||||
'AphrontRedirectResponse' => 'aphront/response/redirect',
|
'AphrontRedirectResponse' => 'aphront/response/redirect',
|
||||||
'AphrontReloadResponse' => 'aphront/response/reload',
|
'AphrontReloadResponse' => 'aphront/response/reload',
|
||||||
|
@ -961,6 +962,7 @@ phutil_register_library_map(array(
|
||||||
'AphrontQueryObjectMissingException' => 'AphrontQueryException',
|
'AphrontQueryObjectMissingException' => 'AphrontQueryException',
|
||||||
'AphrontQueryParameterException' => 'AphrontQueryException',
|
'AphrontQueryParameterException' => 'AphrontQueryException',
|
||||||
'AphrontQueryRecoverableException' => 'AphrontQueryException',
|
'AphrontQueryRecoverableException' => 'AphrontQueryException',
|
||||||
|
'AphrontQuerySchemaException' => 'AphrontQueryException',
|
||||||
'AphrontRedirectException' => 'AphrontException',
|
'AphrontRedirectException' => 'AphrontException',
|
||||||
'AphrontRedirectResponse' => 'AphrontResponse',
|
'AphrontRedirectResponse' => 'AphrontResponse',
|
||||||
'AphrontReloadResponse' => 'AphrontRedirectResponse',
|
'AphrontReloadResponse' => 'AphrontRedirectResponse',
|
||||||
|
|
|
@ -293,27 +293,32 @@ class AphrontMySQLDatabaseConnection extends AphrontDatabaseConnection {
|
||||||
$error = mysql_error($connection);
|
$error = mysql_error($connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$exmsg = "#{$errno}: {$error}";
|
||||||
|
|
||||||
switch ($errno) {
|
switch ($errno) {
|
||||||
case 2013: // Connection Dropped
|
case 2013: // Connection Dropped
|
||||||
case 2006: // Gone Away
|
case 2006: // Gone Away
|
||||||
throw new AphrontQueryConnectionLostException("#{$errno}: {$error}");
|
throw new AphrontQueryConnectionLostException($exmsg);
|
||||||
case 1213: // Deadlock
|
case 1213: // Deadlock
|
||||||
case 1205: // Lock wait timeout exceeded
|
case 1205: // Lock wait timeout exceeded
|
||||||
throw new AphrontQueryRecoverableException("#{$errno}: {$error}");
|
throw new AphrontQueryRecoverableException($exmsg);
|
||||||
case 1062: // Duplicate Key
|
case 1062: // Duplicate Key
|
||||||
// NOTE: In some versions of MySQL we get a key name back here, but
|
// 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
|
// 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
|
// portable to parse the key out of the error and attach it to the
|
||||||
// exception.
|
// exception.
|
||||||
throw new AphrontQueryDuplicateKeyException("{$errno}: {$error}");
|
throw new AphrontQueryDuplicateKeyException($exmsg);
|
||||||
case 1044: // Access denied to database
|
case 1044: // Access denied to database
|
||||||
case 1045: // Access denied (auth)
|
case 1045: // Access denied (auth)
|
||||||
case 1142: // Access denied to table
|
case 1142: // Access denied to table
|
||||||
case 1143: // Access denied to column
|
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:
|
default:
|
||||||
// TODO: 1064 is syntax error, and quite terrible in production.
|
// TODO: 1064 is syntax error, and quite terrible in production.
|
||||||
throw new AphrontQueryException("#{$errno}: {$error}");
|
throw new AphrontQueryException($exmsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ phutil_require_module('phabricator', 'storage/exception/connection');
|
||||||
phutil_require_module('phabricator', 'storage/exception/connectionlost');
|
phutil_require_module('phabricator', 'storage/exception/connectionlost');
|
||||||
phutil_require_module('phabricator', 'storage/exception/duplicatekey');
|
phutil_require_module('phabricator', 'storage/exception/duplicatekey');
|
||||||
phutil_require_module('phabricator', 'storage/exception/recoverable');
|
phutil_require_module('phabricator', 'storage/exception/recoverable');
|
||||||
|
phutil_require_module('phabricator', 'storage/exception/schema');
|
||||||
|
|
||||||
phutil_require_module('phutil', 'error');
|
phutil_require_module('phutil', 'error');
|
||||||
phutil_require_module('phutil', 'serviceprofiler');
|
phutil_require_module('phutil', 'serviceprofiler');
|
||||||
|
|
34
src/storage/exception/schema/AphrontQuerySchemaException.php
Normal file
34
src/storage/exception/schema/AphrontQuerySchemaException.php
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
12
src/storage/exception/schema/__init__.php
Normal file
12
src/storage/exception/schema/__init__.php
Normal 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');
|
Loading…
Reference in a new issue