Skip to content

Commit 4e88184

Browse files
committed
Throw animate API errors whne gd is not a plot
1 parent c85c3a2 commit 4e88184

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

Diff for: src/plot_api/plot_api.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -2486,8 +2486,7 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
24862486
gd = getGraphDiv(gd);
24872487

24882488
if(!Lib.isPlotDiv(gd)) {
2489-
Lib.warn('This element is not a Plotly plot.', gd);
2490-
return Promise.reject();
2489+
throw new Error('This element is not a Plotly plot: ' + gd);
24912490
}
24922491

24932492
var trans = gd._transitionData;
@@ -2770,8 +2769,7 @@ Plotly.addFrames = function(gd, frameList, indices) {
27702769
gd = getGraphDiv(gd);
27712770

27722771
if(!Lib.isPlotDiv(gd)) {
2773-
Lib.warn('This element is not a Plotly plot.', gd);
2774-
return Promise.reject();
2772+
throw new Error('This element is not a Plotly plot: ' + gd);
27752773
}
27762774

27772775
var i, frame, j, idx;
@@ -2780,8 +2778,7 @@ Plotly.addFrames = function(gd, frameList, indices) {
27802778

27812779

27822780
if(!Array.isArray(frameList)) {
2783-
Lib.warn('addFrames failure: frameList must be an Array of frame definitions', frameList);
2784-
return Promise.reject();
2781+
throw new Error('addFrames failure: frameList must be an Array of frame definitions' + frameList);
27852782
}
27862783

27872784
// Create a sorted list of insertions since we run into lots of problems if these
@@ -2859,8 +2856,7 @@ Plotly.deleteFrames = function(gd, frameList) {
28592856
gd = getGraphDiv(gd);
28602857

28612858
if(!Lib.isPlotDiv(gd)) {
2862-
Lib.warn('This element is not a Plotly plot.', gd);
2863-
return Promise.reject();
2859+
throw new Error('This element is not a Plotly plot: ' + gd);
28642860
}
28652861

28662862
var i, idx;

Diff for: test/jasmine/tests/animate_test.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,16 @@ describe('Test animate API', function() {
9494
destroyGraphDiv();
9595
});
9696

97-
it('throws an error if the div is not a plot', function(done) {
98-
var gd2 = createGraphDiv(gd);
97+
it('throws an error if gd is not a graph', function() {
98+
var gd2 = document.createElement('div');
99+
gd2.id = 'invalidgd';
100+
document.body.appendChild(gd2);
99101

100-
// Then = fail, rejection = success
101-
Plotly.animate(gd2).then(fail).catch(done);
102+
expect(function() {
103+
Plotly.addFrames(gd2, [{}]);
104+
}).toThrow(new Error('This element is not a Plotly plot: [object HTMLDivElement]'));
105+
106+
document.body.removeChild(gd);
102107
});
103108

104109
runTests(0);

0 commit comments

Comments
 (0)