-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean ActiveRecord::RecordNotUnique error message
Like we've done before for `PG::UniqueViolation`, sanitize the `ActiveRecord::RecordNotUnique` message. The `RecordNotUnique` error class is a type of error that wraps around errors from database adapter gems like the "pg" gem's `PG::UniqueViolation`. The message for this `RecordNotUnique` error is the same for `PG::UniqueViolation` in this case, prefixed with error class name. Fixes #833
- Loading branch information
Showing
3 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
.changesets/sanitize-activerecord::recordnotunique-error-messages.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
bump: "patch" | ||
type: "add" | ||
--- | ||
|
||
Sanitize `ActiveRecord::RecordNotUnique` error messages to not include any database values that is not unique in the database. This ensures no personal information is sent to AppSignal through error messages from this error. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1364,6 +1364,25 @@ def session_exists?(_env) | |
expect(subject).to eq "ERROR: duplicate key value violates unique constraint \"index_users_on_email\" DETAIL: Key (email)=(?) already exists." | ||
end | ||
end | ||
|
||
context "with a ActiveRecord::RecordNotUnique" do | ||
before do | ||
stub_const("ActiveRecord::RecordNotUnique", Class.new(StandardError)) | ||
end | ||
|
||
let(:error) do | ||
ActiveRecord::RecordNotUnique.new( | ||
"PG::UniqueViolation: ERROR: duplicate key value violates unique constraint \"example_constraint\"\n" \ | ||
"DETAIL: Key (email)=([email protected]) already exists." | ||
) | ||
end | ||
|
||
it "returns a sanizited error message" do | ||
expect(subject).to eq \ | ||
"PG::UniqueViolation: ERROR: duplicate key value violates unique constraint \"example_constraint\"\n" \ | ||
"DETAIL: Key (email)=(?) already exists." | ||
end | ||
end | ||
end | ||
|
||
describe ".to_hash / .to_h" do | ||
|