Skip to content

Commit

Permalink
Improving error messages for option-state initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghnuberath committed Apr 29, 2018
1 parent 7ea5719 commit bd6d27c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions demo/dev-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ window.setQuery = async function () {
{field: 'Keywords', value: ['Rob', 'Phil', 'two']},
{field: 'GeoHash', value: 'geohash things'}
]);
// await lex.setQuery([
// {field: options[0], relation: new OptionStateOption('is like'), value: new OptionStateOption('Sean')},
// {field: options[1], relation: new OptionStateOption('equals'), value: new OptionStateOption('12')}
// ]);
} catch (err) {
console.log('Something went wrong');
console.error(err);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@uncharted/lex",
"description": "A preact framework for building token-based search bars",
"version": "0.16.1",
"version": "0.16.2",
"publishConfig": {
"registry": "nexus.uncharted.software"
},
Expand Down
9 changes: 6 additions & 3 deletions src/lib/states/generic/option-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,14 @@ export class OptionState extends StateTemplate {
await super.initialize();
if (initialUnboxedValues.length > 0) {
await this.fetchOptions(initialUnboxedValues.map(v => this.unformatUnboxedValue(v)), context);
if (!this.allowUnknown && this.options.length !== initialUnboxedValues.length) {
throw new Error(`OptionState ${this.name} cannot accept user-supplied values, but could not fetch matching options for initial values: [${initialUnboxedValues.join(',')}].`);
}
} else {
await this.refreshOptions('', context);
}
if (!this.allowUnknown && this.options.length === 0) {
throw new Error(`OptionState ${this.name} cannot accept user-supplied values, but does not have any options.`);
if (!this.allowUnknown && this.options.length === 0) {
throw new Error(`OptionState ${this.name} cannot accept user-supplied values, but does not have any options.`);
}
}
}

Expand Down

0 comments on commit bd6d27c

Please sign in to comment.