Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c3.generate error catching not working on server #960

Closed
guilherme-salome opened this issue Jan 31, 2015 · 3 comments
Closed

c3.generate error catching not working on server #960

guilherme-salome opened this issue Jan 31, 2015 · 3 comments
Labels
C-bug Category: This is a bug resolved maybe

Comments

@guilherme-salome
Copy link

Problem: c3.generate is not throwing errors when uploaded to server
JSFiddle: http://jsfiddle.net/xq6wmyvp/10/

Code explanation: the code (in the fiddle) has a function that initializes a chart with a line graph using some data. The path to the data is given as a variable to that function (which is called 'initialize(path)'). This function uses c3.generate to create the graph. If the data is not available or does not exist, c3.generate throws an error (this works locally, but not when uploaded to a server - this is the problem) and the function (initialize) returns false. If the data exists, the graph is loaded and 'initialize' returns true.

Problem Restated: after uploading the code to a server, the function 'initialize(path)' only returns 'true', even if the data is not available/non-existent.

I don't know how to solve this. Can you help me?
Thanks for reading!

@guilherme-salome guilherme-salome changed the title c3 not throwing error? c3.generate error catching not working on server (help please) Feb 1, 2015
@guilherme-salome guilherme-salome changed the title c3.generate error catching not working on server (help please) c3.generate error catching not working on server Feb 3, 2015
@guilherme-salome
Copy link
Author

(Answer: http://stackoverflow.com/questions/28262940/c3-generate-not-throwing-error)

Under the hood c3 is using a d3.xhr to retrieve the data. This is an async call meaning that it's outside of your try block.

Possible workarounds include:

  1. Fix it in the c3 source code At line 1903, you see the error is being dropped.
  2. Create a global error handler.
  3. Don't use c3's url option. Issue your own d3 xhr request and, if successful, then call c3.generate with the columns option. Example below:
d3.csv("path/to/file.csv", function(error, json) {
  if (error){
      // handle error properly
      return;
  }
  c3.generate({
    ...
  });
});

@masayuki0812
Copy link
Member

Fixed to throw an error when data.url is not found (and get some error in d3.xhr). I'll release this in the next version v0.4.11. Thanks!

@masayuki0812 masayuki0812 added C-bug Category: This is a bug resolved maybe labels Feb 26, 2015
@masayuki0812
Copy link
Member

0.4.10 has been released, so let me close at the moment. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug resolved maybe
Projects
None yet
Development

No branches or pull requests

2 participants