Description
When the gnuplot
program generates an error that isn't output instantly, GnuplotRB::Plot#plot
loops forever and never displays the error message. This can come up in a number of ways and is particularly sinister because it hides the root cause of many different problems.
The code is reading the output of a separate process, so depending on execution order, you may not run into this problem. Sometimes just running it again works. But many times, it doesn't.
This may be somewhat related to #10. But I was trying to create a heatmap and ran into this. After hacking around it, I found that it's not related to a specific type of plot, but any error.
This is my workaround:
diff --git a/lib/gnuplotrb/plot.rb b/lib/gnuplotrb/plot.rb
index 1fb46f6..1809107 100644
--- a/lib/gnuplotrb/plot.rb
+++ b/lib/gnuplotrb/plot.rb
@@ -79,6 +79,7 @@ module GnuplotRB
ds_string = @datasets.map { |dataset| dataset.to_s(terminal) }.join(' , ')
full_command = @cmd + ds_string
terminal.set(inner_opts).stream_puts(full_command).unset(inner_opts.keys)
+ sleep 1
if inner_opts[:output]
# guaranteed wait for plotting to finish
terminal.close unless term
It's unsatisfactory because it sleeps unnecessarily, especially in non-error cases.
I think many people would appreciate having this fixed since showing the underlying error message is crucial, especially for new users (like me) who aren't familiar with what options they should be using. What ends up happening is people experiment with different options to see what happens. Unfortunately, as it is now, that often causes them to get stuck, not knowing how to proceed.