Skip to content

Commit

Permalink
Better error messages and target selection logic (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
ceriottm authored Sep 13, 2024
1 parent 7fed362 commit 01f8ee4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 3 additions & 7 deletions src/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,17 +302,13 @@ export function getTarget(dataset: Dataset): DisplayTarget {
// Target is specified in settings
if (target !== undefined) {
if (target === 'atom' && dataset.environments === undefined) {
throw new Error('To use "atom" target, "settings.properties" should be provided');
}
if (getTargetProps(target).length < 2) {
throw new Error(
`The provided target (${target}) cannot be used. Make sure there are at least two corresponding properties ('settings.properties').`
);
throw new Error('To use "atom" target, a list of environments should be provided');
}
return target;
}
// Default to atom properties if there are environments AND atomic properties
const atomProperties = getTargetProps('atom');
return dataset.environments !== undefined && atomProperties.length > 1 ? 'atom' : 'structure';
return dataset.environments !== undefined && atomProperties.length > 0 ? 'atom' : 'structure';
}

function checkMetadata(o: JsObject) {
Expand Down
6 changes: 5 additions & 1 deletion src/map/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ export class MapOptions extends OptionsGroup {

// Setup axes
const propertiesName = Object.keys(properties);
assert(propertiesName.length >= 2);
if (propertiesName.length < 2) {
throw new Error(
'Cannot show a map because the dataset contains fewer than two properties.'
);
}
this.x = new AxisOptions(propertiesName);
this.y = new AxisOptions(propertiesName);
// For z and color '' is a valid value
Expand Down

0 comments on commit 01f8ee4

Please sign in to comment.