Skip to content

Add assertion IDs that will be included in production log statements for fail and hardAsserts #8313

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 21 commits into from
Apr 14, 2025

Conversation

MarkDuckworth
Copy link
Contributor

@MarkDuckworth MarkDuckworth commented Jun 12, 2024

In the Firestore SDK, error messages are removed from fail(message) and hardAssert(condition, message) statements during the build. Removal of error messages is performed to reduce bundle size, however this comes at a cost to usability. Specifically, this means that production error messages can be unhelpful.

Here's an example of a production error message today (without this change):

FIRESTORE (1.2.3) INTERNAL ASSERTION FAILED: Unexpected state

"Unexpected state" is the same reason given for 130+ error conditions after the detailed error messages have been stripped.

To improve debuggability of error messages, this PR adds a numeric assertion ID to each fail and hardAssert statement. These numeric IDs are unique and will not be removed from the build output. The full error message will still be removed during the build, but the assertion IDs introduced with this change will give customers and support more information to debug the output.

Here's and example of a production error message after this change is applied:

FIRESTORE (1.2.3) INTERNAL ASSERTION FAILED: Unexpected state (ID: 0x2e4a) CONTEXT: {"example": "relevant JSON serialized state of the application when the assertion failed."}

Scripts:
yarn assertion-id:new - Create a new unique ID
yarn assertion-id:check - Check for duplicate and invalid id formatting
yarn assertion-id:find <ID> - Find an existing ID and the error message associated with it
yarn assertion-id:list - list all of the existing IDs and their error messages

@MarkDuckworth MarkDuckworth requested review from a team as code owners June 12, 2024 17:42
Copy link

changeset-bot bot commented Jun 12, 2024

🦋 Changeset detected

Latest commit: 833f972

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@firebase/firestore Patch
firebase Patch
@firebase/firestore-compat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Jun 12, 2024

Changeset File Check ✅

  • No modified packages are missing from the changeset file.
  • No changeset formatting errors detected.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 12, 2024

Size Report 1

Affected Products

  • @firebase/data-connect

    TypeBase (933ba9d)Merge (8d4a221)Diff
    browser21.4 kB21.4 kB+5 B (+0.0%)
    main23.6 kB23.7 kB+51 B (+0.2%)
    module21.4 kB21.4 kB+5 B (+0.0%)
  • @firebase/firestore

    TypeBase (933ba9d)Merge (8d4a221)Diff
    browser382 kB384 kB+2.48 kB (+0.6%)
    main591 kB594 kB+3.22 kB (+0.5%)
    module382 kB384 kB+2.48 kB (+0.6%)
    react-native382 kB384 kB+2.47 kB (+0.6%)
  • @firebase/firestore-lite

    TypeBase (933ba9d)Merge (8d4a221)Diff
    browser113 kB114 kB+984 B (+0.9%)
    main155 kB157 kB+1.42 kB (+0.9%)
    module113 kB114 kB+984 B (+0.9%)
    react-native113 kB114 kB+984 B (+0.9%)
  • bundle

    15 size changes

    TypeBase (933ba9d)Merge (8d4a221)Diff
    firestore (CSI Auto Indexing Disable and Delete)272 kB274 kB+1.95 kB (+0.7%)
    firestore (CSI Auto Indexing Enable)272 kB274 kB+1.95 kB (+0.7%)
    firestore (Persistence)304 kB306 kB+2.18 kB (+0.7%)
    firestore (Query Cursors)250 kB251 kB+1.31 kB (+0.5%)
    firestore (Query)248 kB249 kB+1.31 kB (+0.5%)
    firestore (Read data once)236 kB237 kB+1.28 kB (+0.5%)
    firestore (Read Write w Persistence)328 kB330 kB+2.24 kB (+0.7%)
    firestore (Realtime updates)238 kB239 kB+1.30 kB (+0.5%)
    firestore (Transaction)215 kB216 kB+1.25 kB (+0.6%)
    firestore (Write data)214 kB216 kB+1.20 kB (+0.6%)
    firestore-lite (Query Cursors)104 kB104 kB+702 B (+0.7%)
    firestore-lite (Query)99.9 kB101 kB+702 B (+0.7%)
    firestore-lite (Read data once)75.4 kB75.9 kB+543 B (+0.7%)
    firestore-lite (Transaction)101 kB101 kB+786 B (+0.8%)
    firestore-lite (Write data)85.0 kB85.5 kB+572 B (+0.7%)

  • firebase

    TypeBase (933ba9d)Merge (8d4a221)Diff
    firebase-compat.js794 kB797 kB+2.42 kB (+0.3%)
    firebase-data-connect.js17.6 kB17.9 kB+358 B (+2.0%)
    firebase-firestore-compat.js340 kB342 kB+2.43 kB (+0.7%)
    firebase-firestore-lite.js131 kB132 kB+984 B (+0.7%)
    firebase-firestore.js440 kB443 kB+2.42 kB (+0.5%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/moJiZXEFA3.html

@dconeybe
Copy link
Contributor

IMO adding 2.4 kB to the bundle size is questionable if it's worth it.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 12, 2024

Size Analysis Report 1

This report is too large (723,339 characters) to be displayed here in a GitHub comment. Please use the below link to see the full report on Google Cloud Storage.

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/jHq10E6LcE.html

@MarkDuckworth
Copy link
Contributor Author

MarkDuckworth commented Jun 12, 2024

IMO adding 2.4 kB to the bundle size is questionable if it's worth it.

@dconeybe, in your opinion, what increase in bundle size would be acceptable?

It's <=1% increase, which seems like a reasonable tradeoff for making production issues more debuggable. But I'm seeing if I can make the impact smaller.

@dconeybe
Copy link
Contributor

IMO adding 2.4 kB to the bundle size is questionable if it's worth it.

@dconeybe, in your opinion, what increase in bundle size would be acceptable?

It's <=1% increase, which seems like a reasonable tradeoff for making production issues more debuggable. But I'm seeing if I can make the impact smaller.

I'd hope it would be less than 1kB. But this is just one man's opinion. Please don't take it as gospel truth.

Copy link
Contributor

@dconeybe dconeybe left a comment

Choose a reason for hiding this comment

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

This is fantastic! I especially like how you added the "context" which will be incredibly useful when debugging. Thanks for doing this, Mark.

@dconeybe
Copy link
Contributor

dconeybe commented Apr 2, 2025

Please let the team know about the 1% increase in code bundle size and make sure they're ok with it. The "firestore (Read Write w Persistence)" bundle increased by 2.77 kB which is probably worth it, but I'd make sure the team knows.

Also, please add a change set with a minor version bump and a change log entry.

Copy link
Contributor

@hsubox76 hsubox76 left a comment

Choose a reason for hiding this comment

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

Reminder to add a changeset if you want it to publish.

@dconeybe
Copy link
Contributor

dconeybe commented Apr 3, 2025

FWIW I much prefer the "hashes" you had before over error codes numerically incrementing from zero. The reason is that hashes have much better "SEO" because of their uniqueness. Firstly, the improved SEO allows customers to search for the error code and find relevant bug reports, stack overflow posts, etc. If they search for error code "3" they won't likely get anything useful, but if they search for "jszxcbe37k" they'll likely get results that relate directly to the error that they are experiencing. Likewise, when we as Firestore SDK developers get a bug report with error code "3" it's much more difficult to find its place in the source code than searching for "jszxcbe37k".

For Data Connect I chose this alphabet: [23456789abcdefghjkmnopqrstuvwxyz](https://github.com/firebase/firebase-android-sdk/blob/a0a02a73f67f6447c739d920f614c8bd5331c591/firebase-dataconnect/src/main/kotlin/com/google/firebase/dataconnect/util/AlphanumericStringUtil.kt#L31C45-L31C79) (a length of 32). This alphabet is most of the English lowercase letters and most digits, with those that "look alike" removed (e.g. zero "0" and lowercase-o "o"). This leads to incredibly unique 6-digit strings.

@MarkDuckworth MarkDuckworth requested a review from a team as a code owner April 3, 2025 13:23
@MarkDuckworth MarkDuckworth changed the title Implement solution to replace error messages with error codes, instead of removing error messages. Add assertion IDs that will be included in production log statements for fail and hardAsserts Apr 8, 2025
@MarkDuckworth MarkDuckworth requested a review from hsubox76 April 8, 2025 15:33
Copy link
Contributor

@dconeybe dconeybe left a comment

Choose a reason for hiding this comment

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

Mostly LGTM. Just a few minor comments. Thanks for doing this work! I'll formally "approve" once the comments are addressed/refuted.

@MarkDuckworth MarkDuckworth requested a review from dconeybe April 8, 2025 23:46
Copy link
Contributor

Vertex AI Mock Responses Check ⚠️

A newer major version of the mock responses for Vertex AI unit tests is available. update_vertexai_responses.sh should be updated to clone the latest version of the responses: v10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants