Skip to content

Firestore: Fix "missing index" error message #6712

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 15 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/little-rats-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@firebase/firestore': patch
'firebase': patch
---

Fix "missing index" error message to include the create composite index link.
60 changes: 32 additions & 28 deletions packages/firestore/test/integration/api/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ import {
apiDescribe,
toChangesArray,
toDataArray,
withEmptyTestCollection,
withTestCollection,
withTestDb
} from '../util/helpers';
import { USE_EMULATOR } from '../util/settings';

apiDescribe('Queries', (persistence: boolean) => {
addEqualityMatcher();
Expand Down Expand Up @@ -649,35 +651,37 @@ apiDescribe('Queries', (persistence: boolean) => {
});
});

it('can catch error message for missing index with error handler', () => {
const testDocs = {
'1': { sort: 1, filter: true, key: '1' },
'2': { sort: 2, filter: true, key: '2' }
};
return withTestCollection(persistence, testDocs, async coll => {
const query_ = query(
coll,
where('sort', '<=', '2'),
where('filter', '==', true)
);
const deferred = new Deferred<void>();
// eslint-disable-next-line no-restricted-properties
(USE_EMULATOR ? it.skip : it)(
'can catch error message for missing index with error handler',
() => {
return withEmptyTestCollection(persistence, async coll => {
const query_ = query(
coll,
where('sort', '<=', '2'),
where('filter', '==', true)
);
const deferred = new Deferred<void>();

const unsubscribe = onSnapshot(
query_,
() => {},
err => {
expect(err.code).to.equal('failed-precondition');
expect(err.message).to.exist;
expect(err.message).to.match(
/index.*https:\/\/console\.firebase\.google\.com/
);
deferred.resolve();
}
);
await deferred.promise;
unsubscribe();
});
});
const unsubscribe = onSnapshot(
query_,
() => {
deferred.reject();
},
err => {
expect(err.code).to.equal('failed-precondition');
expect(err.message).to.exist;
expect(err.message).to.match(
/index.*https:\/\/console\.firebase\.google\.com/
);
deferred.resolve();
}
);
await deferred.promise;
unsubscribe();
});
}
);

it('can explicitly sort by document ID', () => {
const testDocs = {
Expand Down