Not stopping processing of configs upon first error, collecting all errors
Publish PHP Package / docker (push) Successful in 6s
Details
Publish PHP Package / docker (push) Successful in 6s
Details
This commit is contained in:
parent
dd8c4311b7
commit
7a6208d921
|
@ -201,6 +201,8 @@ class ConfigFetchResult
|
|||
public array $by_path = array();
|
||||
/** @var array<string, ConfigCacheEntry> */
|
||||
public array $by_alias = array();
|
||||
/** @var array<string, string> */
|
||||
public array $errors = array();
|
||||
public int $stales = 0;
|
||||
public int $corruptions = 0;
|
||||
public int $fast_jsons = 0;
|
||||
|
@ -233,6 +235,20 @@ function config_cache_fetch(ConfigFetchParams $params) : ConfigFetchResult
|
|||
|
||||
$result = _config_cache_fetch($params);
|
||||
|
||||
if($result->errors)
|
||||
{
|
||||
$errors = array();
|
||||
foreach($result->errors as $file => $error)
|
||||
{
|
||||
$errors[] = (count($errors) + 1) . ") Error in file '$file': $error";
|
||||
if(count($errors) > 15)
|
||||
break;
|
||||
}
|
||||
var_dump(sizeof($errors));
|
||||
|
||||
throw new Exception(implode("\n", $errors));
|
||||
}
|
||||
|
||||
if($params->verbose)
|
||||
config_log("Fetch from cache: " . round(microtime(true) - $t,2) . " sec.");
|
||||
|
||||
|
@ -306,7 +322,13 @@ function _config_merge_fetch_results(ConfigFetchParams $params, array $results_b
|
|||
{
|
||||
foreach($results as $item)
|
||||
{
|
||||
list($base_dir, $file, $cache_file, $is_stale, $parser_type) = $item;
|
||||
list($base_dir, $file, $cache_file, $is_stale, $parser_type, $error) = $item;
|
||||
|
||||
if($error !== null)
|
||||
{
|
||||
$result->errors[$file] = $error;
|
||||
continue;
|
||||
}
|
||||
|
||||
if($parser_type === 1)
|
||||
++$total_fast_jsons;
|
||||
|
|
|
@ -27,7 +27,7 @@ function config_parse(array $base_dirs, string $file) : ConfigParseResult
|
|||
catch(Exception $e)
|
||||
{
|
||||
$res->error = 1;
|
||||
$res->error_descr = "File '$file':\n" . $e->getMessage() . "\n" . $e->getTraceAsString();
|
||||
$res->error_descr = $e->getMessage() . "\n" . $e->getTraceAsString();
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
|
15
task.inc.php
15
task.inc.php
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
namespace taskman;
|
||||
use Exception;
|
||||
use Throwable;
|
||||
|
||||
task('config_worker', function(array $args)
|
||||
{
|
||||
|
@ -17,7 +18,7 @@ task('config_worker', function(array $args)
|
|||
$result = _config_worker_func($params, $job);
|
||||
ensure_write($out_file, serialize($result));
|
||||
}
|
||||
catch(Exception $e)
|
||||
catch(Throwable $e)
|
||||
{
|
||||
//NOTE: explicitely catching all exceptions and writing to the error file
|
||||
// since under Windows error file stream redirect may work unreliably
|
||||
|
@ -45,7 +46,7 @@ function _config_worker_run_procs(ConfigFetchParams $params, array $jobs, bool $
|
|||
}
|
||||
}
|
||||
|
||||
//returns [[base_dir, file, cache_file, was_stale], ...]
|
||||
//returns [[base_dir, file, cache_file, was_stale, parser_type, error], ...]
|
||||
function _config_worker_func(ConfigFetchParams $params, array $job) : array
|
||||
{
|
||||
$start_time = microtime(true);
|
||||
|
@ -60,10 +61,10 @@ function _config_worker_func(ConfigFetchParams $params, array $job) : array
|
|||
$results = array();
|
||||
foreach($chunk as $file_idx => $chunk_data)
|
||||
{
|
||||
list($base_dir, $file) = $chunk_data;
|
||||
|
||||
try
|
||||
{
|
||||
list($base_dir, $file) = $chunk_data;
|
||||
|
||||
if($params->verbose && $file_idx > 0 && ($file_idx % 500) == 0)
|
||||
config_log("Worker $idx progress: " . round($file_idx / sizeof($chunk) * 100) . "% ...");
|
||||
|
||||
|
@ -78,11 +79,11 @@ function _config_worker_func(ConfigFetchParams $params, array $job) : array
|
|||
if($is_stale)
|
||||
_config_invalidate_cache($params, $base_dir, $file, $cache_file, $parser_type);
|
||||
|
||||
$results[] = array($base_dir, $file, $cache_file, $is_stale, $parser_type);
|
||||
$results[] = array($base_dir, $file, $cache_file, $is_stale, $parser_type, null);
|
||||
}
|
||||
catch(Exception $e)
|
||||
catch(Throwable $e)
|
||||
{
|
||||
throw new Exception("Error in file '$file': " . $e->getMessage());
|
||||
$results[] = array($base_dir, $file, null, null, null, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue