Skip to content

Improved error messages for custom types #162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 21, 2018

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Mar 21, 2018

This addresses #143

This PR changes two of our error messages:

  • When we detect an custom object during serialization, we throw: 'Firestore doesn't support serialization of JavaScript objects that were constructed using the 'new' operator.'
  • When we detect an invalid type as method argument, we throw: 'Cannot use object of type "FieldPath" as a Firestore argument.'

There might be much better ways to express this, and the easiest way to figure out if the changes here make sense is to look at the test cases that show these error messages.

Note that the code tested in order.js is not reachable from customer code. The tests exists to allow for 100% coverage (touches line

throw validate.customObjectError(val);
)

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 21, 2018
@codecov
Copy link

codecov bot commented Mar 21, 2018

Codecov Report

Merging #162 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #162   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          12     12           
  Lines        1729   1731    +2     
=====================================
+ Hits         1729   1731    +2
Impacted Files Coverage Δ
src/document.js 100% <100%> (ø) ⬆️
src/validate.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9cc94f4...ff04a5d. Read the comment docs.

src/validate.js Outdated
default:
return new Error(
"Firestore doesn't support serialization of JavaScript objects " +
"that were constructed using the 'new' operator."

This comment was marked as spam.

This comment was marked as spam.


assert.throws(() => {
firestore
.doc('collectionId/documentId')
.set({foo: Firestore.FieldPath.documentId()});
}, /Cannot use "FieldPath" as a Firestore type./);
}, /Cannot use object of type "FieldPath" as a Firestore value./);

This comment was marked as spam.

This comment was marked as spam.

Copy link
Contributor

@mikelehen mikelehen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@schmidt-sebastian schmidt-sebastian merged commit 3668407 into master Mar 21, 2018
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt-constructormessage branch May 22, 2018 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants