com web/qa: Be more verbose in case of error.: pulls/api.php pulls/pullrequests.js
| From: | Johannes Schlüter | Date: | Tue, 20 Mar 2012 20:06:57 +0000 |
| Subject: | com web/qa: Be more verbose in case of error.: pulls/api.php pulls/pullrequests.js | ||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66157@lists.php.net to get a copy of this message | ||
Commit: a47b17e778bf30d113ada1410a2f87665201145e
Author: Johannes Schlüter <johannes@php.net> Tue, 20 Mar 2012 21:06:57 +0100
Parents: df34f7ffed7c031f5fec4eb812ebe105b75575a3
Branches: master
Link: http://git.php.net/?p=web/qa.git;a=commitdiff;h=a47b17e778bf30d113ada1410a2f87665201145e
Log:
Be more verbose in case of error.
Changed paths:
M pulls/api.php
M pulls/pullrequests.js
Diff:
a47b17e778bf30d113ada1410a2f87665201145e
diff --git a/pulls/api.php b/pulls/api.php
index c6f747c..e55477d 100644
--- a/pulls/api.php
+++ b/pulls/api.php
@@ -1,4 +1,5 @@
<?php
+$errors = array();
require('./config.php');
if ($_SERVER['SERVER_NAME'] === 'schlueters.de') {
@@ -53,6 +54,8 @@ function verify_password_DEV($user, $pass)
function ghpostcomment($pull, $comment)
{
+ global $errors;
+
$post = json_encode(array("body" => "**Comment on behalf of $_SESSION[user] at
php.net:**\n\n$comment"));
@@ -64,8 +67,21 @@ function ghpostcomment($pull, $comment)
$ctx = stream_context_create(array('http' => $opts));
$url = str_replace('https://', 'https://'.GITHUB_USER.':'.GITHUB_PASS.'@',
$pull->_links->comments->href);
+ $old_track_errors = ini_get('track_errors');
+ ini_set('track_errors', true);
$s = @file_get_contents($url, false, $ctx);
- return (bool)$s;
+ ini_set('track_errors', $old_track_errors);
+
+ if (!$s) {
+ $errors[] = "Server responded: ".$http_response_header[0];
+ $errors[] = "Github user: ".GITHUB_USER;
+ if ($_SESSION['user'] === 'johannes') {
+ /* This might include the password or such, so not everybody should get it */
+ $errors[] = $php_errormsg;
+ }
+ return false;
+ }
+ return true;
}
function ghchangestate($pull, $state)
@@ -118,6 +134,8 @@ function loggedin()
function ghupdate()
{
+ global $errors;
+
if (empty($_SESSION['user'])) {
header('HTTP/1.0 401 Unauthorized');
die(json_encode(array('success' => false, 'errors' =>
array('Unauthorized'))));
@@ -154,13 +172,15 @@ function ghupdate()
if (!ghpostcomment($pull, $comment)) {
header('500 Internal Server Error');
- die(json_encode(array('success' => false, 'errors' =>
array("Failed to add comment on GitHub"))));
+ $errors[] = "Failed to add comment on GitHub";
+ die(json_encode(array('success' => false, 'errors' => $errors)));
}
if (!empty($_POST['state'])) {
if (!ghchangestate($pull, $_POST['state'])) {
header('500 Internal Server Error');
- die(json_encode(array('success' => false, 'errors' =>
array("Failed to set new state"))));
+ $errors[] = "Failed to set new state";
+ die(json_encode(array('success' => false, 'errors' => $errors)));
}
}
diff --git a/pulls/pullrequests.js b/pulls/pullrequests.js
index f1cbbd8..bacdb6c 100644
--- a/pulls/pullrequests.js
+++ b/pulls/pullrequests.js
@@ -148,7 +148,19 @@ function updateRepo(reponame, num, dia) {
id: num,
state: $("select", dia)..attr("value"),
comment: $("textarea", dia).attr("value")
- }, success: function(d) { loadRepo(reponame); } });
+ }, success: function(d) {
+ if (d.success) {
+ loadRepo(reponame);
+ } else {
+ /* This might be reported in a nicer way ... */
+ var message = "Failed while updating!";
+ var key;
+ for (key in d.errors) {
+ message += "\n"+d.errors[key];
+ }
+ window.alert(message);
+ }
+ });
dia.dialog("destroy");
}