Getting a better error message if I forget to define the value for a placeholder, when querying a Realm.
I would love a message that said: "Query uses the $0 placeholder but a value was not provided".
An error is thrown with "vector" as message.
const schema: Realm.ObjectSchema[] = [{
name: 'Person',
properties: {
name: 'string',
age: 'int',
}
}];
realm.objects('Person').filtered('name != $0');
import * as assert from 'assert';
import * as Realm from 'realm';
const schema: Realm.ObjectSchema[] = [
{
name: 'Person',
properties: {
name: 'string',
age: 'int',
}
}
];
describe('Realm filtering with an undefined placeholder', () => {
let realm: Realm;
before(() => {
// Open a local realm
assert(!realm);
realm = new Realm({ path: 'test.realm', schema });
});
after(() => {
if (realm) {
if (!realm.isClosed) {
realm.close();
}
Realm.deleteFile({ path: realm.path });
}
});
it('throws a meaningful message', (done) => {
// First we create a collection
const persons = realm.objects('Person');
assert.equal(persons.length, 0);
try {
const filteredPersons = persons.filtered('age > $0');
} catch (err) {
assert.notEqual(err.message, 'vector');
}
});
});
We might actually have to fix it in core. @ironage
Better error reporting in currently in review.
The fix is included in core 5.6.1.
See #1859
2.8.3 has been released.
Thanks guys!
Most helpful comment
2.8.3 has been released.