Skip to content

Add /eval/<id>/errors REST endpoint#1583

Open
kmein wants to merge 1 commit intoNixOS:masterfrom
kmein:feature/rest-errors
Open

Add /eval/<id>/errors REST endpoint#1583
kmein wants to merge 1 commit intoNixOS:masterfrom
kmein:feature/rest-errors

Conversation

@kmein
Copy link
Copy Markdown
Member

@kmein kmein commented Mar 18, 2026

Description

When querying the /eval/<id>/errors endpoint via the REST API (Accept: application/json), the response previously returned the standard JobsetEval metadata but completely omitted the actual evaluation error message.

Root cause:
Due to previous database optimizations, errormsg is lazy-loaded and stored in the EvaluationErrors relation. While the eval-error.tt HTML template correctly traversed the prefetched evaluationerror object, passing the raw DBIx object to Catalyst's $self->status_ok() caused the JSON serializer to drop the joined table data entirely.

Solution:
This explicitly extracts the evaluationerror data into a plain hash before passing it to status_ok. It also introduces a clean has_error boolean to make it easier for API consumers to check for failures.

Example Output

Testing with curl -H "Accept: application/json" http://localhost:3000/eval/<id>/errors | jq .

When an error exists:

{
  "id": 2,
  "has_error": true,
  "errormsg": "in job ‘x86_64-linux.broken’:\nerror:\n       … while calling the 'throw' builtin..."
}

When no error exists:

{
  "id": 2,
  "has_error": false,
  "errormsg": ""
}

Copilot AI review requested due to automatic review settings March 18, 2026 15:47
@kmein kmein force-pushed the feature/rest-errors branch from bc5e29e to 3d60bca Compare March 18, 2026 15:50
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to fix the /eval/<id>/errors REST endpoint so that JSON responses include the evaluation error message (errormsg) that was previously omitted due to lazy-loading/serialization behavior around the EvaluationErrors relation.

Changes:

  • Refetches JobsetEval with evaluationerror prefetched for the /eval/<id>/errors endpoint.
  • Builds a plain hash response containing id, a new has_error boolean, and errormsg for JSON serialization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +107 to +113
my $has_error = ($err_str ne '') ? \1 : \0;

my $response = {
id => $eval->id,
has_error => $has_error,
errormsg => $err_str,
};
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not doing $has_error any more. And having real booleans in the JSON makes sense.

Comment on lines +109 to +113
my $response = {
id => $eval->id,
has_error => $has_error,
errormsg => $err_str,
};
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, the JSON API of this endpoint was not specified at all in the OpenAPI schema. (Of course, this does not mean it wasn't relied upon, though it's unlikely given that it did exactly the same thing as the normal JobsetEval endpoint without /errors). I've added OpenAPI docs now.

Comment on lines +98 to +105
my $eval = $c->model('DB::JobsetEvals')->find(
$c->stash->{eval}->id,
{ prefetch => 'evaluationerror' }
);

$c->stash->{eval} = $eval;

my $error_obj = $eval->evaluationerror;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works as well, at least if you re-add

    $c->stash->{eval} = $c->model('DB::JobsetEvals')->find(
        $c->stash->{eval}->id,
        { prefetch => 'evaluationerror' }
    );

But I would like to see a human opinion on this matter. I don't know enough Perl to trust a clanker with it.

Comment on lines +106 to +107
my $err_str = $error_obj ? $error_obj->errormsg : '';
my $has_error = ($err_str ne '') ? \1 : \0;
Copy link
Copy Markdown
Member Author

@kmein kmein Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope:

DBIx::Class::Row::get_column(): No such column 'has_error' on Hydra::Model::DB::EvaluationErrors at /home/kfm/src/hydra/subprojects/hydra/script/../lib/Hydra/Controller/JobsetEval.pm line 107

@kmein kmein force-pushed the feature/rest-errors branch 2 times, most recently from 0653b77 to 5f87c31 Compare March 18, 2026 16:00
@kmein kmein requested a review from Copilot March 18, 2026 16:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses missing evaluation error text in the /eval/<id>/errors REST endpoint when requesting JSON by returning a plain hash payload instead of a raw DBIx object (which dropped joined relation data during serialization). It also documents the endpoint in the OpenAPI spec.

Changes:

  • Update /eval/<id>/errors controller logic to build an explicit JSON entity containing id, has_error, and errormsg.
  • Add OpenAPI path + schema for /eval/{eval-id}/errors.
  • Minor OpenAPI formatting/example adjustments.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
subprojects/hydra/lib/Hydra/Controller/JobsetEval.pm Builds an explicit response entity for /eval/<id>/errors instead of serializing the DBIx row directly.
hydra-api.yaml Documents the new /eval/{eval-id}/errors endpoint and adds a JobsetEvalErrors schema.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Previously, returning the DBIx object directly to status_ok caused the
JSON serializer to ignore the joined evaluationerror table. This explicitly
maps the required fields into a hash to ensure errormsg and has_error
are exposed to REST clients.
@kmein kmein force-pushed the feature/rest-errors branch from 5f87c31 to 35f301d Compare March 18, 2026 16:11
@kmein kmein changed the title Fix missing errormsg in /eval/<id>/errors REST endpoint Add /eval/<id>/errors REST endpoint Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants