Realm-js: Forgetting placeholder value should throw a meaningful error

Created on 18 May 2018  路  6Comments  路  Source: realm/realm-js

Goals

Getting a better error message if I forget to define the value for a placeholder, when querying a Realm.

Expected Results

I would love a message that said: "Query uses the $0 placeholder but a value was not provided".

Actual Results

An error is thrown with "vector" as message.

Steps to Reproduce

Define a schema

const schema: Realm.ObjectSchema[] = [{
  name: 'Person',
  properties: {
    name: 'string',
    age: 'int',
  }
}];

Query data

realm.objects('Person').filtered('name != $0');

馃敟

Code Sample

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');
    }
  });
});

Version of Realm and Tooling

  • Realm JS SDK Version: 2.6.0
  • Node or React Native: N/A
  • Client OS & Version: N/A
  • Which debugger for React Native: N/A
P-2-Expected T-Bug

Most helpful comment

2.8.3 has been released.

All 6 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CrystalRanita picture CrystalRanita  路  3Comments

bdebout picture bdebout  路  3Comments

kevinnguy picture kevinnguy  路  3Comments

kontinuity picture kontinuity  路  3Comments

MihaelIsaev picture MihaelIsaev  路  3Comments