Firestore error codes do not change. Can the same be said for Firestore error messages?
I have a transaction that creates two docs, and if some doc exists, it either aborts or retries (depending on which doc).
Right now, we’ve correctly implemented via read/write/write, but there are non-negligible cost savings for removing the read. As of today, the error message contains a parseable resource path (for the failed write).
I’m wondering if the message text is considered stable (like the error code), or if it is subject to change.
2
Answers
According to official Google Cloud documentation:
google.rpc.Status
objects, which containstatus
,message
, anddetails
message
is "subject to changes without notice"status
anddetails
are appropriate for programmatic use, and "developers should use these payloads whenever possible"Therefore, while
message
parsing is not guaranteed to be reliable, it is safe to parse the content ofdetails
, since this is intended for developer use.As a general rule, for all software, you should not depend on the contents of error messages to make decisions programmatically. The only exception to this is if there is documentation that suggests that error messages are meant to be parsed by another program. (And if that were the case, why wouldn’t the developers of the software just put that data in a struct as part of the thrown error, and document that struct so you don’t have to parse anything?)
There is nothing in Firestore documentation that suggests error messages can or should be parsed. If you want to do that, do it at your own risk, since a small change in implementation could break your program. If you want a hard guarantee that error messages will never change for the lifetime of the product, then Stack Overflow is not the right place to get that. You should address Firebase staff directly by either contacting Firebase support, or perhaps posting to firebase-talk.