aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/errors.rb
Commit message (Collapse)AuthorAgeFilesLines
* Use `try` only when we're unsure if the receiver would respond_to the methodAkira Matsuda2019-08-011-1/+1
|
* Move DatabaseAlreadyExists detection to DB adapterJohn Hawthorn2019-07-291-0/+4
| | | | | | | | | | | | | | | | | | | | Previously it was the responsibility of the database tasks to translate the invalid statement from creating a duplicate database into an ActiveRecord::Tasks::DatabaseAlreadyExists error. It's actually easier for us to do this detection inside of the adapter, where we already do a case statement on the return code to translate the error. This commit introduces ActiveRecord::DatabaseAlreadyExists, a subclass of StatementInvalid, and updates both AbstractMysqlAdapter and PostgresqlAdapter to return this more specific exception in that case. Because this is a subclass of the old exception, StatementInvalid, it should be backwards compatible with any code expecting that from create_database. This works for both create_database and exectute("CREATE DATABASE")
* Update links to new MySQL server errors reference page [ci skip]Carlos Antonio da Silva2019-07-271-1/+1
|
* [ActiveRecord] Superclass for aborted queriesKir Shatrov2019-07-161-3/+7
|
* Add missing period [ci skip]Rafael Mendonça França2019-07-161-1/+1
|
* Raise specific exception on Mysql2::Error::TimeoutErrorKir Shatrov2019-07-161-0/+4
|
* Better error message for calling columns_hashGuilherme Mansur2019-06-191-0/+4
| | | | | | | | | | | | When a record does not have a table name, as in the case for a record with `self.abstract_class = true` and no `self.table_name` set the error message raises a cryptic: "ActiveRecord::StatementInvalid: Could not find table ''" this patch now raises a new `TableNotSpecified Error` Fixes: #36274 Co-Authored-By: Eugene Kenny <elkenny@gmail.com>
* Replace “can not” with “cannot”.Samantha John2019-03-061-1/+1
|
* Fix the regex that extract mismatched foreign key informationRyuta Kamizono2019-02-171-12/+17
| | | | | | | | | | | | | The CI failure for `test_errors_for_bigint_fks_on_integer_pk_table` is due to the poor regex that extract all ``` `(\w+)` ``` like parts from the message (`:foreign_key` should be `"old_car_id"`, but `"engines"`): https://travis-ci.org/rails/rails/jobs/494123455#L1703 I've improved the regex more strictly and have more exercised mismatched foreign key tests. Fixes #35294
* Rename error that occurs when writing on a readEileen Uchitelle2018-12-071-0/+4
| | | | | | | I originally named this `StatementInvalid` because that's what we do in GitHub, but `@tenderlove` pointed out that this means apps can't test for or explitly rescue this error. `StatementInvalid` is pretty broad so I've renamed this to `ReadOnlyError`.
* Redact SQL in errorsGannon McGibbon2018-11-221-3/+7
| | | | | Move `ActiveRecord::StatementInvalid` SQL to error property. Also add bindings as an error property.
* MySQL: Raise ActiveRecord::InvalidForeignKey for foreign-key constraint ↵George Claghorn2018-07-301-1/+2
| | | | violations on delete
* Fix frozen string concatenation by indicating that it's mutableRafael Mendonça França2018-02-161-2/+2
| | | | References 89bcca5
* Remove usage of strip_heredoc in the framework in favor of <<~Rafael Mendonça França2018-02-161-2/+2
| | | | | Some places we can't remove because Ruby still don't have a method equivalent to strip_heredoc to be called in an already existent string.
* Add new error class `QueryCanceled` which will be raised when canceling ↵Ryuta Kamizono2017-11-271-0/+4
| | | | | | | | | | | | | | | statement due to user request (#31235) This changes `StatementTimeout` to `QueryCanceled` for PostgreSQL. In MySQL, errno 1317 (`ER_QUERY_INTERRUPTED`) is only used when the query is manually cancelled. But in PostgreSQL, `QUERY_CANCELED` error code (57014) which is used `StatementTimeout` is also used when the both case. And, we can not tell which reason happened. So I decided to introduce new error class `QueryCanceled` closer to the error code name.
* Rename `TransactionTimeout` to more descriptive `LockWaitTimeout` (#31223)Ryuta Kamizono2017-11-271-2/+2
| | | | | | Since #31129, new error class `StatementTimeout` has been added. `TransactionTimeout` is caused by the timeout shorter than `StatementTimeout`, but its name is too generic. I think that it should be a name that understands the difference with `StatementTimeout`.
* Merge pull request #27947 from mastahyeti/unsafe_raw_sqlMatthew Draper2017-11-141-0/+25
|\ | | | | | | Disallow raw SQL in dangerous AR methods
| * allow Arel.sql() for pluckBen Toews2017-11-091-0/+25
| |
* | Add new error class `StatementTimeout` which will be raised when statement ↵Ryuta Kamizono2017-11-131-2/+5
|/ | | | | | | | | | | | timeout exceeded (#31129) We are sometimes using The MAX_EXECUTION_TIME hint for MySQL depending on the situation. It will prevent catastrophic performance down by wrong performing queries. The new error class `StatementTimeout` will make to be easier to handle that case. https://dev.mysql.com/doc/refman/5.7/en/optimizer-hints.html#optimizer-hints-execution-time
* Add TransactionTimeout for MySQL error code 1205Gabriel Courtemanche2017-08-221-0/+5
|
* [ci skip] Postgres --> PostgreSQLRyuta Kamizono2017-08-081-1/+1
|
* Change http postgresql.org links to https [ci skip]yuuji.yaginuma2017-07-301-1/+1
| | | | | It seems that it accepts only HTTPS connections. Ref: https://github.com/postgres/postgres/commit/7f77cbd996855a06fb742ea11adbe55c42b48fe2
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* [ci skip] UNIQUE constraint affects not only INSERT but also UPDATERyuta Kamizono2017-06-061-1/+1
|
* Remove original_exception from ActiveRecord::StatementInvalidRafael Mendonça França2016-12-291-11/+1
|
* Translate numeric value out of range to the specific exceptionRyuta Kamizono2016-12-061-0/+4
| | | | Raise `ActiveRecord::RangeError` when values that executed are out of range.
* Merge pull request #25451 from ↵Sean Griffin2016-12-061-0/+4
|\ | | | | | | | | kamipo/translate_not_null_violation_to_specific_exception Translate NOT NULL violation to the specific exception
| * Translate NOT NULL violation to the specific exceptionRyuta Kamizono2016-12-061-0/+4
| | | | | | | | | | Raise `ActiveRecord::NotNullViolation` when a record cannot be inserted or updated because it would violate a not null constraint.
* | Should inherit `StatementInvalid` rather than `WrappedDatabaseException`Ryuta Kamizono2016-12-061-1/+1
|/ | | | Because defunct wrapper class is kept for compatibility.
* Make pg adapter use bigserial for pk by defaultPavel Pravosud2016-12-051-0/+28
|
* Add missing `+` around a some literals.bogdanvlviv2016-10-271-1/+1
| | | | | | Mainly around `nil` [ci skip]
* applies remaining conventions across the projectXavier Noria2016-08-061-3/+0
|
* The problem isn't the detection but the deadlock itselfDavid Heinemeier Hansson2016-08-041-2/+2
|
* Merge pull request #25107 from Erol/introduce-new-ar-transaction-error-classesRafael Mendonça França2016-08-031-2/+12
|\ | | | | | | | | | | Introduce new ActiveRecord transaction error classes Closes #26018
| * Introduce new ActiveRecord transaction error classesErol Fornoles2016-05-241-2/+12
| |
* | `TransactionSerializationError` should inherit `StatementInvalid` for ↵Ryuta Kamizono2016-08-021-1/+1
|/ | | | | | | backward compatibility Originally `TransactionSerializationError` was `StatementInvalid` in Rails 5.0. It should keep backward compatibility.
* Add AR::TransactionSerializationError for transaction serialization failures ↵Erol Fornoles2016-05-211-0/+10
| | | | or deadlocks
* Merge pull request #23522 from kamipo/add_value_too_long_exception_classJeremy Daer2016-04-181-0/+4
|\ | | | | | | Add `ActiveRecord::ValueTooLong` exception class
| * Add `ActiveRecord::ValueTooLong` exception classRyuta Kamizono2016-02-061-0/+4
| |
* | Merge pull request #22170 from ↵Matthew Draper2016-03-021-0/+5
|\ \ | |/ |/| | | | | samphilipd/sam/properly_deallocate_prepared_statements_outside_of_transaction Correctly deallocate prepared statements if we fail inside a transaction
| * Correctly deallocate prepared statements if we fail inside a transactionSam Davies2015-11-051-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Addresses issue #12330 Overview ======== Cached postgres prepared statements become invalidated if the schema changes in a way that it affects the returned result. Examples: - adding or removing a column then doing a 'SELECT *' - removing the foo column then doing a 'SELECT bar.foo' In normal operation this isn't a problem, we can rescue the error, deallocate the prepared statement and re-issue the command. However in PostgreSQL transactions, once any command fails, the transaction becomes 'poisoned' and any subsequent commands will raise InFailedSQLTransaction. This includes DEALLOCATE statements, so the default deallocation strategy instead of removing the cached prepared statement instead raises InFailedSQLTransaction. Why this is bad =============== 1. InFailedSQLTransaction is a fairly cryptic error and doesn't communicate any useful information about what has actually gone wrong. 2. In the naive implementation the prepared statement never gets deallocated - it stays alive for the length of the session taking up memory on the postgres server. 3. It is unsafe to retry the transaction because the bad prepared statement is still in the cache and we would see the exact same failure repeated. Solution ======== If we are outside a transaction we can continue to handle these failures gracefully in the usual way. Inside a transaction instead of issuing a DEALLOCATE command that will certainly fail, we now raise ActiveRecord::PreparedStatementCacheExpired. This can be handled further up the stack, notably inside TransactionManager#within_new_transaction. Here we can make sure to first rollback the transaction, then safely issue DEALLOCATE statements to invalidate the rest of the cached prepared statements. This also allows the user (or some gem) the opportunity to catch this error and voluntarily retry the transaction if a schema change causes the prepared statement cache to become invalidated. Because the outdated statement has been deallocated, we can expect the transaction to succeed on the second try.
* | Introduce ActiveRecord::IrreversibleOrderErrorBogdan Gusiev2016-01-271-0/+5
| | | | | | | | | | Raises when #reverse_order can not process SQL order instead of making invalid SQL before this patch
* | Remove legacy mysql adapterRyuta Kamizono2015-12-211-1/+1
|/ | | | Follow up to #22642.
* Deprecate exception#original_exception in favor of exception#causeYuki Nishijima2015-11-031-4/+12
|
* applies new doc guidelines to Active Record.Yves Senn2015-10-141-18/+28
| | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* Make ActiveRecordException descendants args optionalPavel Pravosud2015-09-071-15/+23
| | | | | | This change allows to instantiate all ActiveRecordError descendant execption classes without arguments, which might be useful in testing and is far less surprising than mandatory arguments.
* uniqueness validation raises error for persisted record without pk.Yves Senn2015-08-201-3/+4
| | | | | | | | Closes #21304. While we can validate uniqueness for record without primary key on creation, there is no way to exclude the current record when updating. (The update itself will need a primary key to work correctly).
* Extra caller details added to ActiveRecord::RecordNotFoundSameer Rahmani2015-07-211-0/+9
| | | | | | | | | | | | | | | | ActiveRecord::RecordNotFound modified to store model name, primary_key and id of the caller model. It allows the catcher of this exception to make a better decision to what to do with it. For example consider this simple example: class SomeAbstractController < ActionController::Base rescue_from ActiveRecord::RecordNotFound, with: :redirect_to_404 private def redirect_to_404(e) return redirect_to(posts_url) if e.model == 'Post' raise end end