fix: tell export clients which terms the chosen format cannot hold [T-2599]
Merged
EV
6d ago+181+181+012345678901234567890123456789-15-15-01234567890123456789
What was wrong
Some projects cannot be exported in some formats: a project with the terms app and app.title in jsonnested, yamlnested or php, or a project with a term @x in arb. On develop (e0acd75):
api/src/formatters/nested-key-conflict.tsandapi/src/formatters/arb.ts:45-47build a message that names the terms, for exampleNested JSON cannot hold the term "app" together with "app.title": ....api/src/controllers/exports.controller.ts:163-164,:174-175,:189-190and:200-201wrap that message in a plainBadRequestException.api/src/filters/exception.filter.ts:88-92answers every 400 with the fixed messageYour request seems to be invalid or malformed, so the terms are lost.- The webapp downloads the export with
responseType: 'blob'(webapp/src/app/projects/services/export.service.ts:25). Its error body is a Blob that nobody reads (webapp/src/app/shared/util/api-error.ts:46), so the webapp shows a general hint without the term.
API clients got "invalid or malformed", and webapp users got a hint with no term name. In a large project, neither could tell which term to rename.
What changed
api/src/errors/index.ts: newFormatCannotHoldTermsException, a subclass ofBadRequestException.exports.controller.ts: the four catches (jsonnested, yamlnested, php, arb) now throw this exception instead of a plainBadRequestException. The 400 description in the Swagger decorator says that the message names the terms.exception.filter.ts: answers this exception with status 400, codeBadRequestand the exception's own message. The check comes right afterAuthProviderExceptionand before the database checks. Some of those checks match on the message text (UNIQUE constraint failed), and a quoted term name could contain that text. Every other 400 still gets the fixed message.webapp/.../export.service.ts: when an export fails with 400 and the body is a Blob, the service parses it as JSON and rethrows theHttpErrorResponsewith the parsed body. If the body cannot be parsed, the original error is rethrown unchanged.webapp/.../api-error.ts: for a failedExportLocalewith status 400, the webapp shows the API's message when there is one. Otherwise it shows the same general hint as before.docs/changelog.md: one line undernext.docs/api/v1/errors.md: the 400 section shows the new message.
The response shape and status do not change: still 400 { error: { code: 'BadRequest', message } }. Only the message text is new.
Tests (written first, failing before the fix)
api/src/filters/exception.filter.spec.ts: three new tests. (1) The new exception keeps its message. (2) It keeps its message even when that message quotesUNIQUE constraint failed. (3) A plainBadRequestExceptionstill gets the fixed message.- On develop the suite does not compile (
TS2305: Module '"../errors"' has no exported member 'FormatCannotHoldTermsException'). With only the exception class added and the filter unchanged: 2 failed, 3 passed (Received: "Your request seems to be invalid or malformed", andExpected: 400, Received: 409for the quoted database error). - After: 5 of 5 passed.
- On develop the suite does not compile (
api/test/export.e2e-spec.ts:308: forjsonnested,yamlnestedandphp, the test now also checks that the message containscannot hold the term "button" together with "button.tooltip". A new test creates the term@x, exports inarb, and checks for 400 withrename these terms before exporting: @x.- Before (SQLite): 2 failed, 10 passed (
Received string: "Your request seems to be invalid or malformed"). - After: 12 of 12 passed on SQLite, Postgres 15 and MySQL 5.7.
- Before (SQLite): 2 failed, 10 passed (
webapp/.../export-locale.component.spec.ts: the component runs with the realExportServiceagainstHttpTestingController. The export is answered with 400 and a Blob body. (1) A JSON body: the component shows the API's message. (2) A body that is not JSON: the component shows the general hint.- Before: 1 failed, 4 passed (the component showed the general hint, not the message).
- After: 5 of 5 passed.
Checks run (Windows, Node 24)
yarn check-fmtat the root (prettier --check "**/*.ts"): all files use Prettier code style.yarn --cwd api lint: clean.tsc -p api/tsconfig.json --noEmit: clean.- api unit tests (
yarn --cwd api test,--maxWorkers=2): 198 of 199 passed, 28 of 29 suites. The one failure issrc/formatters/properties.spec.ts"should export properties files", which this PR does not touch. It fails only on Windows, because thepropertieslibrary writes\r\non win32. CircleCI and GitHub Actions run on Linux. - api e2e, full suite on SQLite (
jest --config ./test/jest-e2e.json --runInBand --forceExit): 21 of 21 suites, 190 of 190 tests passed. - api e2e on Postgres 15 (throwaway container, same settings as
ci.yml):export.e2e-spec.tspassed 12 of 12. I started the full suite on Postgres, but on this shared PC each suite took about ten times as long as on SQLite. I stopped it after 4 of 21 suites, all passed, and left the full Postgres and MySQL runs to theapi-e2eCI matrix. - api e2e on MySQL 5.7 (throwaway container, data on tmpfs because the shared PC's disk made each migration run take minutes):
export.e2e-spec.tspassed 12 of 12. - webapp unit tests (
yarn test --watch=false --browsers=ChromeHeadlessCI --progress=false, as CI runs them): 65 of 65 passed.
Fleet task T-2599; authored by the lead lane while the fleet is paused by its daily cost ceiling.
š¤ Generated with Claude Code