Skip to content

Commit 42cde0d

Browse files
committed
Improve error reporting in start-errors.php
1 parent eb45e41 commit 42cde0d

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

scripts/start-servers.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,16 @@ function make_ctx($preset, $method = "POST") {
4747
return $ctx;
4848
}
4949

50-
function failed($result) {
51-
echo "\n\n";
52-
echo join("\n", $result);
53-
printf("Last operation took: %.2f secs\n", lap());
54-
exit();
55-
}
56-
5750
function mo_http_request($uri, $context) {
5851
global $http_response_header;
5952

6053
$result = file_get_contents($uri, false, $context);
6154

6255
if ($result === false) {
63-
failed($http_response_header);
56+
printf("HTTP request to %s failed:\n", $uri);
57+
var_dump($http_response_header);
58+
printf("Last operation took: %.2f secs\n", lap());
59+
exit(1);
6460
}
6561

6662
return $result;
@@ -109,7 +105,8 @@ function json_decode_or_fail(/* json_decode() args */)
109105
$decode = json_decode_or_fail($result, true);
110106

111107
if (!isset($decode["id"])) {
112-
failed($decode);
108+
printf("\"id\" field not found in server response:\n%s\n", $decode);
109+
exit(1);
113110
}
114111

115112
$SERVERS[$decode["id"]] = isset($decode["mongodb_auth_uri"]) ? $decode["mongodb_auth_uri"] : $decode["mongodb_uri"];
@@ -126,8 +123,10 @@ function json_decode_or_fail(/* json_decode() args */)
126123
$decode = json_decode_or_fail($result, true);
127124

128125
if (!isset($decode["id"])) {
129-
failed($decode);
126+
printf("\"id\" field not found in replica set response:\n%s\n", $decode);
127+
exit(1);
130128
}
129+
131130
$SERVERS[$decode["id"]] = isset($decode["mongodb_auth_uri"]) ? $decode["mongodb_auth_uri"] : $decode["mongodb_uri"];
132131
printf("'%s'\t(took: %.2f secs)\n", $SERVERS[$decode["id"]], lap());
133132
}

0 commit comments

Comments
 (0)