Skip to content

Commit

Permalink
Display graphviz error messages, if any
Browse files Browse the repository at this point in the history
This simply passes through graphviz's error messages if the invocation
doesn't succeed. I guess that beats a completely generic error message.
  • Loading branch information
jast committed May 26, 2011
1 parent a34c4e6 commit 7fe1026
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions gen.php
Expand Up @@ -55,16 +55,26 @@ function goto_output($id)
$def = "$type G {\n$def\n}\n";
$engine = ($type == 'graph') ? 'neato' : 'dot';

$p = proc_open("/usr/bin/$engine -Tpng", array(0 => array('pipe', 'r'), 1 => array('pipe', 'w')), $pipes);
$p = proc_open("/usr/bin/$engine -Tpng", array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
if (!is_resource($p)) die("Couldn't start graphing engine, sorry!");
fwrite($pipes[0], $def);
fclose($pipes[0]);

$png = stream_get_contents($pipes[1]);
fclose($pipes[1]);

$err = stream_get_contents($pipes[2]);
fclose($pipes[2]);

$res = proc_close($p);
if ($res != 0) die("Couldn't create graph, sorry!");
if ($res != 0): ?>
<p>Couldn't create graph, sorry! Error message follows:
<pre><?php echo htmlspecialchars($err); ?></pre>
<p>The graph definition was:
<pre><?php echo htmlspecialchars($def); ?></pre>
<?php
exit;
endif;

$png = mysql_real_escape_string($png);
$def = mysql_real_escape_string($def);
Expand Down

0 comments on commit 7fe1026

Please sign in to comment.