Skip to content

Commit

Permalink
Merge pull request #29 from smgallo/etl/improve-jsonfile-logging
Browse files Browse the repository at this point in the history
Improve ETL JSON data endpoint filter logging
  • Loading branch information
smgallo authored Jan 19, 2017
2 parents 08c2dea + 3aee162 commit fd58879
Showing 1 changed file with 41 additions and 37 deletions.
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

0 comments on commit fd58879

Please sign in to comment.