Skip to content

fix: fix/error message upload [Backport release/0.5.z]#1138

Merged
carlosthe19916 merged 1 commit into
release/0.5.zfrom
backport-1111-to-release/0.5.z
Jul 2, 2026
Merged

fix: fix/error message upload [Backport release/0.5.z]#1138
carlosthe19916 merged 1 commit into
release/0.5.zfrom
backport-1111-to-release/0.5.z

Conversation

@trustify-ci-bot

@trustify-ci-bot trustify-ci-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Description

Backport of #1111 to release/0.5.z.

Summary by Sourcery

Improve upload error handling to surface API-provided messages for advisory and SBOM uploads.

Bug Fixes:

  • Ensure Axios upload errors display structured API error, message, and optional details instead of generic messages.

Enhancements:

  • Extend getAxiosErrorMessage to handle multiple response shapes including error/message/details strings and plain-text bodies.
  • Update file upload UI assertions to validate displayed helper-text error messages when uploads fail.

Tests:

  • Add unit tests for getAxiosErrorMessage covering various Axios error payload shapes.
  • Add shared E2E helper and scenarios to verify advisory and SBOM upload flows show the correct API error message.

Signed-off-by: Carlos Feria <2582866+carlosthe19916@users.noreply.github.com>
(cherry picked from commit 319e799)
@sourcery-ai

sourcery-ai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Backport that centralizes Axios upload error message extraction in a shared utility and aligns UI + e2e tests with the new behavior for advisory and SBOM uploads.

Sequence diagram for centralized Axios upload error handling

sequenceDiagram
  actor User
  participant UploadFiles
  participant getAxiosErrorMessage

  User->>UploadFiles: upload file
  UploadFiles-->>UploadFiles: HTTP request via Axios
  UploadFiles-->>UploadFiles: [error response received]
  UploadFiles->>getAxiosErrorMessage: getAxiosErrorMessage(axiosError)
  getAxiosErrorMessage-->>UploadFiles: errorMessage
  UploadFiles-->>User: show errorMessage
Loading

Flow diagram for getAxiosErrorMessage decision logic

flowchart TD
  A[AxiosError received] --> B{response data exists}
  B -->|no| H[Return axiosError.message]
  B -->|yes| C{data.error and data.message are strings}
  C -->|yes| D[base = error: message]
  D --> E{data.details is string}
  E -->|yes| F[Return base + '\n' + details]
  E -->|no| G[Return base]
  C -->|no| I{data.message is string}
  I -->|yes| J[Return data.message]
  I -->|no| K{data.error is string}
  K -->|yes| L[Return data.error]
  K -->|no| M{data is string}
  M -->|yes| N[Return data]
  M -->|no| H[Return axiosError.message]
Loading

File-Level Changes

Change Details Files
Refine getAxiosErrorMessage to parse structured API error responses and cover behaviors with unit tests.
  • Update getAxiosErrorMessage to read error, message, and details fields from Axios response data, with fallbacks to plain string body or axiosError.message.
  • Add a local AxiosError factory helper in tests to build minimal error objects for different shapes of response data.
  • Extend utils tests with cases for combined error+message, inclusion of details, message-only, error-only, plain string body, and unknown fields handling.
client/src/app/utils/utils.ts
client/src/app/utils/utils.test.ts
Make file upload UI assertions aware of error messages and add a reusable e2e helper for upload API error message verification.
  • Extend FileUploadMatchers to optionally assert a helper-text message for success or danger status instead of only checking the progress percentage.
  • Introduce testUploadApiErrorMessage helper that stubs API responses and validates the rendered per-file error message in the upload component.
  • Use helper-text variants mapped from status (danger -> error, success -> default) when asserting messages in the uploader.
e2e/tests/ui/assertions/FileUploadMatchers.ts
e2e/tests/ui/pages/common/upload-test-helpers.ts
Wire advisory and SBOM upload pages to use the shared Axios error message utility and add e2e coverage for their upload error messages.
  • Replace inline extractErrorMessage lambdas in advisory and SBOM upload pages with getAxiosErrorMessage from the shared utils module.
  • Remove unused AxiosError type imports now that the extractor is a shared utility function.
  • Add e2e tests for advisory and SBOM uploads that simulate InvalidFormat API errors and verify the user-facing error message matches the parsed API error.
client/src/app/pages/advisory-upload/advisory-upload.tsx
client/src/app/pages/sbom-upload/sbom-upload.tsx
e2e/tests/ui/pages/advisory-upload/upload.spec.ts
e2e/tests/ui/pages/sbom-upload/upload.spec.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@carlosthe19916 carlosthe19916 changed the title fix: Fix/error message upload [Backport release/0.5.z] fix: fix/error message upload [Backport release/0.5.z] Jul 2, 2026
@carlosthe19916 carlosthe19916 merged commit bd8fe4d into release/0.5.z Jul 2, 2026
12 of 13 checks passed

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In getAxiosErrorMessage, consider tightening the signature to AxiosError<unknown> and introducing a small runtime type guard for the data shape so you can drop the any and the eslint disable while still keeping the logic safe and explicit.
  • In toHaveItemUploadStatus, when an expectedStatus.message is provided you no longer assert on the progress reaching 100%; for status: "success" you may still want to keep the 100% progress assertion to ensure the upload completed in addition to checking the message.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `getAxiosErrorMessage`, consider tightening the signature to `AxiosError<unknown>` and introducing a small runtime type guard for the `data` shape so you can drop the `any` and the eslint disable while still keeping the logic safe and explicit.
- In `toHaveItemUploadStatus`, when an `expectedStatus.message` is provided you no longer assert on the progress reaching 100%; for `status: "success"` you may still want to keep the 100% progress assertion to ensure the upload completed in addition to checking the message.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-project-automation github-project-automation Bot moved this to Done in Trustify Jul 2, 2026
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.34%. Comparing base (96c9508) to head (3b4674a).
⚠️ Report is 3 commits behind head on release/0.5.z.

Additional details and impacted files
@@                Coverage Diff                @@
##           release/0.5.z    #1138      +/-   ##
=================================================
+ Coverage          51.10%   51.34%   +0.24%     
=================================================
  Files                256      256              
  Lines               5522     5523       +1     
  Branches            1672     1672              
=================================================
+ Hits                2822     2836      +14     
+ Misses              2432     2421      -11     
+ Partials             268      266       -2     
Flag Coverage Δ
unit 6.38% <100.00%> (+0.26%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant