Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ETL JSON data endpoint filter logging #29

Merged
merged 2 commits into from
Jan 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 41 additions & 37 deletions classes/ETL/DataEndpoint/JsonFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
use JsonSchema\Validator;
use Symfony\Component\Process\ProcessBuilder;

class JsonFile extends StructuredFile
implements iDataEndpoint
class JsonFile extends StructuredFile implements iDataEndpoint
{
/**
* A JSON Schema describing each element in an array-based JSON file.
Expand Down Expand Up @@ -78,12 +77,17 @@ public function parse($returnArray = false)
$this->logAndThrowException("No valid filter options specified for '{$this->path}'.");
}

// Run the filter process.
$filterProc = ProcessBuilder::create($filterProcArgs)->getProcess();
try {
// Run the filter process.
$filterProc = ProcessBuilder::create($filterProcArgs)->getProcess();

$filterProc->run();
if (! $filterProc->isSuccessful()) {
$this->logAndThrowException('Filter Error: ' . $filterProc->getErrorOutput());
$filterProc->run();
if (! $filterProc->isSuccessful()) {
$this->logAndThrowException('Filter Error: ' . $filterProc->getErrorOutput());
}
} catch (Exception $e) {
$msg = "Filter Error (" . implode(", ", $filterProcArgs) . "): " . $e->getMessage();
$this->logAndThrowException($msg);
}

// Parse the filter process's output.
Expand Down Expand Up @@ -188,36 +192,36 @@ private function jsonLastErrorMsg($errorCode)
$message = "";

switch ( $errorCode ) {
case JSON_ERROR_NONE:
$message = "No error has occurred";
break;
case JSON_ERROR_DEPTH:
$message = "The maximum stack depth has been exceeded";
break;
case JSON_ERROR_STATE_MISMATCH:
$message = "Invalid or malformed JSON";
break;
case JSON_ERROR_CTRL_CHAR:
$message = " Control character error, possibly incorrectly encoded";
break;
case JSON_ERROR_SYNTAX:
$message = "Syntax error";
break;
case JSON_ERROR_UTF8:
$message = "Malformed UTF-8 characters, possibly incorrectly encoded";
break;
case JSON_ERROR_RECURSION:
$message = "One or more recursive references in the value to be encoded";
break;
case JSON_ERROR_INF_OR_NAN:
$message = "One or more NAN or INF values in the value to be encoded";
break;
case JSON_ERROR_UNSUPPORTED_TYPE:
$message = "A value of a type that cannot be encoded was given";
break;
default:
$message = "Unknown error";
break;
case JSON_ERROR_NONE:
$message = "No error has occurred";
break;
case JSON_ERROR_DEPTH:
$message = "The maximum stack depth has been exceeded";
break;
case JSON_ERROR_STATE_MISMATCH:
$message = "Invalid or malformed JSON";
break;
case JSON_ERROR_CTRL_CHAR:
$message = " Control character error, possibly incorrectly encoded";
break;
case JSON_ERROR_SYNTAX:
$message = "Syntax error";
break;
case JSON_ERROR_UTF8:
$message = "Malformed UTF-8 characters, possibly incorrectly encoded";
break;
case JSON_ERROR_RECURSION:
$message = "One or more recursive references in the value to be encoded";
break;
case JSON_ERROR_INF_OR_NAN:
$message = "One or more NAN or INF values in the value to be encoded";
break;
case JSON_ERROR_UNSUPPORTED_TYPE:
$message = "A value of a type that cannot be encoded was given";
break;
default:
$message = "Unknown error";
break;
}

return $message;
Expand Down