Filter errors that start with Couldn't add (#42764)

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #42572

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

## Testing

- [x] Added/updated automated tests
- [ ] Where appropriate, [automated tests simulate multiple hosts and
test for host
isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing)
(updates to one hosts's records do not affect another)

- [x] QA'd all new/changed functionality manually
This commit is contained in:
Jonathan Katz 2026-03-31 16:33:55 -04:00 committed by GitHub
parent e35d07c96d
commit 941c49b84e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 58 additions and 1 deletions

View file

@ -0,0 +1 @@
- Fixed duplicate text in error message when script validation fails when adding a custom package

View file

@ -0,0 +1,53 @@
import { getErrorMessage } from "./helpers";
jest.mock("axios", () => {
const actual = jest.requireActual("axios");
return {
...actual,
isAxiosError: () => true,
};
});
describe("getErrorMessage", () => {
it("returns message for pending install/uninstall error", () => {
const err = {
response: {
status: 400,
data: {
errors: [
{
name: "Error",
reason:
"Couldn't install. Host already has a pending install/uninstall for this installer.",
},
],
},
},
};
expect(getErrorMessage(err)).toBe(
"Couldn't add. Couldn't install. Host already has a pending install/uninstall for this installer."
);
});
it("returns message for script validation error", () => {
const err = {
response: {
status: 400,
data: {
errors: [
{
name: "Error",
reason:
"Couldn't add. Script validation failed: Script is too large. It's limited to 500,000 characters (approximately 10,000 lines).",
},
],
},
},
};
expect(getErrorMessage(err)).toBe(
"Couldn't add. Script validation failed: Script is too large. It's limited to 500,000 characters (approximately 10,000 lines)."
);
});
});

View file

@ -22,7 +22,6 @@ export const getErrorMessage = (err: unknown) => {
isAxiosError(err) &&
(err.response?.status === 504 || err.response?.status === 408);
const reason = getErrorReason(err);
if (isTimeout) {
return REQUEST_TIMEOUT_ERROR_MESSAGE;
}
@ -68,6 +67,10 @@ export const getErrorMessage = (err: unknown) => {
);
}
if (reason.startsWith("Couldn't add.")) {
return `${ensurePeriod(reason)}`;
}
if (reason) {
return `${ADD_SOFTWARE_ERROR_PREFIX} ${ensurePeriod(reason)}`;
}