Skip to content

Commit

Permalink
JsonFile::__toString() - detect json_encode failure (#263)
Browse files Browse the repository at this point in the history
* JsonFile::__toString() - detect json_encode failure

* fix CS
  • Loading branch information
keradus committed May 22, 2018
1 parent 1e3edc1 commit 5175585
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Bundle/CoverallsBundle/Entity/Coveralls.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ abstract class Coveralls implements ArrayConvertable
*/
public function __toString()
{
return json_encode($this->toArray());
$result = json_encode($this->toArray());

if (json_last_error() !== JSON_ERROR_NONE) {
throw new \UnexpectedValueException(sprintf(
'Can not encode to JSON, error: "%s". If you have non-UTF8 chars, consider migration to UTF8.',
json_last_error_msg()
));
}

return $result;
}
}

0 comments on commit 5175585

Please sign in to comment.