Skip to content

Commit 1cb70fc

Browse files
committed
pretty print of error messages
1 parent 8f1f270 commit 1cb70fc

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Helper.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,18 @@ public static function resolveURI($parent, $current)
6666
}
6767

6868

69+
public static function padLines($with, $text, $skipFirst = true)
70+
{
71+
$lines = explode("\n", $text);
72+
foreach ($lines as $index => $line) {
73+
if ($skipFirst && !$index) {
74+
continue;
75+
}
76+
if ($line) {
77+
$lines[$index] = $with . $line;
78+
}
79+
}
80+
return implode("\n", $lines);
81+
}
82+
6983
}

src/Schema.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function process($data, Context $options, $path = '#', $result = null)
212212
break;
213213
}
214214
} catch (InvalidValue $exception) {
215-
$failures .= ' ' . $index . ': ' . $exception->getMessage() . "\n";
215+
$failures .= ' ' . $index . ': ' . Helper::padLines(' ', $exception->getMessage()) . "\n";
216216
// Expected exception
217217
}
218218
}
@@ -240,7 +240,7 @@ public function process($data, Context $options, $path = '#', $result = null)
240240
}
241241
}
242242
if (!$successes) {
243-
$this->fail(new LogicException('Failed due to logical constraint: no valid results for anyOf {' . "\n" . substr($failures, 0, -1) . "\n}"), $path);
243+
$this->fail(new LogicException('Failed due to logical constraint: no valid results for anyOf {' . "\n" . substr(Helper::padLines(' ', $failures), 0, -1) . "\n}"), $path);
244244
}
245245
}
246246

0 commit comments

Comments
 (0)