fix: surface Pydantic array validation errors from SCALE 25.04+ API

SCALE 25.04 returns validation errors as a JSON array rather than a
{message: "..."} hash. The error detail was silently lost, making 4xx
failures appear as bare status lines in logs. Now handles both formats.

Prompted by a transient 422 on /iscsi/target during first-run testing
on SCALE 25.04 — root cause was iSCSI service mid-reload, not a format
incompatibility. Plugin is compatible with SCALE 25.04 as-is.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Kevin Adams 2026-05-26 21:12:44 -04:00
parent 2979d54279
commit 7a66e59dc7
1 changed files with 7 additions and 1 deletions

View File

@ -187,7 +187,13 @@ sub _api {
my $detail = '';
eval {
my $body = decode_json($res->content);
$detail = " — $body->{message}" if ref $body eq 'HASH' && $body->{message};
if (ref $body eq 'HASH' && $body->{message}) {
$detail = " — $body->{message}";
} elsif (ref $body eq 'ARRAY' && @$body) {
# SCALE 25.04+ returns Pydantic validation errors as an array
my @msgs = map { $_->{message} // $_->{msg} // '' } @$body;
$detail = " — " . join('; ', grep { length } @msgs);
}
};
my $msg = "TrueNAS API $method $path: " . $res->status_line . $detail;
_log('err', $msg);