Exception: Parse::Client::DuplicateValueError
- Inherits:
-
ResponseError
- Object
- StandardError
- Error
- ResponseError
- Parse::Client::DuplicateValueError
- Defined in:
- lib/parse/client.rb
Overview
An error when a Parse server response carries code 137 (DuplicateValue), typically raised when a unique field (or MongoDB unique index) rejects an insert. Carries the Response for inspection. The synchronize-create wrapper in Parse::Core::Actions rescues this internally and re-queries inside the held lock to return the winning object.
**Message redaction.** Parse Server (and the underlying MongoDB driver) serialize the offending unique-key payload into the error string in two parallel forms: ‘keyValue: { “email”: “user@example.com” }` AND `dup key: { : “user@example.com” }`. Echoing either into application logs exposes the colliding identifier (email, username, account number, external ID) to anyone with log access — turning a duplicate-write error into a unique-field enumeration oracle. The constructor strips both fragments before delegating to `super`. The raw response is preserved on `#response` for callers that legitimately need the unredacted detail (e.g. the synchronize-create wrapper).
Constant Summary collapse
- CODE =
137- KEY_VALUE_PATTERN =
Matches both MongoDB E11000 fragment forms: ‘keyValue: { … }` and `dup key: { … }`. The driver emits the offending unique-key value verbatim in each, so both must be stripped to close the leak.
/(?:keyValue|dup\s*key)\s*:?\s*\{[^}]*\}/i.freeze
- REDACTION =
"[REDACTED]".freeze
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Attributes inherited from Error
Class Method Summary collapse
-
.redact(msg) ⇒ String?
Strip ‘keyValue: { … }` fragments from a message string so the offending unique-constraint value never leaks into log lines.
Instance Method Summary collapse
-
#initialize(response = nil) ⇒ DuplicateValueError
constructor
A new instance of DuplicateValueError.
Constructor Details
#initialize(response = nil) ⇒ DuplicateValueError
Returns a new instance of DuplicateValueError.
236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/parse/client.rb', line 236 def initialize(response = nil) @response = response raw = if response.is_a?(String) response elsif response.respond_to?(:error) response.error else response.to_s end super(self.class.redact(raw)) end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
234 235 236 |
# File 'lib/parse/client.rb', line 234 def response @response end |
Class Method Details
.redact(msg) ⇒ String?
Strip ‘keyValue: { … }` fragments from a message string so the offending unique-constraint value never leaks into log lines. Returns the original message verbatim when it contains no `keyValue:` token, so non-MongoDB-shaped errors are unaffected.
254 255 256 257 258 |
# File 'lib/parse/client.rb', line 254 def self.redact(msg) return msg if msg.nil? s = msg.to_s s.gsub(KEY_VALUE_PATTERN, REDACTION) end |