Skip to content

fix(file-service): apply LakeFS error handling to all call sites - #5607

Merged
Yicong-Huang merged 3 commits into
apache:mainfrom
suyashj1231:fix/lakefs-error-handling
Jun 12, 2026
Merged

Yicong-Huang merged 3 commits into
apache:mainfrom
suyashj1231:fix/lakefs-error-handling

Conversation

@suyashj1231

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

#4177 introduced LakeFSExceptionHandler.withLakeFSErrorHandling, but only the multipart-upload and dataset-version paths used it. The remaining LakeFS call sites in DatasetResource either leaked raw io.lakefs.clients.sdk.ApiException to Dropwizard (an opaque 500 for the frontend) or caught Exception and rewrapped it as a generic 500, discarding the real LakeFS status code (401/403/404/409/...).

Before:  LakeFS 404  ->  raw ApiException / catch(Exception)  ->  500 "Failed to ..."
After:   LakeFS 404  ->  withLakeFSErrorHandling              ->  404 "Error while deleting file 'a.csv' ...: LakeFS resource not found. ..."

Changes:

Change Where
New overload withLakeFSErrorHandling(operation: String)(call) that prefixes the user-visible message with the failed operation LakeFSExceptionHandler.scala
8 bare LakeFS calls now wrapped (size lookup, version listing, zip download, presigned URLs, cover image) DatasetResource.scala
5 catch Exception -> generic 500 blocks now use the handler; compensation logic (DB rollback on failed repo init, multipart abort) is preserved, and the abort-on-failure cleanup no longer masks the original error DatasetResource.scala

Intentionally unchanged: best-effort cleanup sites that deliberately swallow errors, the per-dataset skip in listDatasets, and the FileService startup health check (failing fast at boot is correct there).

Any related issues, documentation, discussions?

Closes #4176

How was this PR tested?

New LakeFSExceptionHandlerSpec (7 unit cases): status-code mapping (400/401/403/404/409/4xx/5xx/unknown), operation context included in the frontend-visible message, success passthrough, and non-LakeFS exceptions propagating untouched.

New integration case in DatasetResourceSpec: deleting a dataset whose LakeFS repository does not exist now yields NotFoundException (404) instead of a generic 500.

sbt "FileService/testOnly org.apache.texera.service.util.LakeFSExceptionHandlerSpec"
# Tests: succeeded 7, failed 0
sbt "FileService/testOnly org.apache.texera.service.resource.DatasetResourceSpec"
# Tests: succeeded 94, failed 0  (Testcontainers: LakeFS 1.51 + MinIO + Postgres)

sbt FileService/scalafixAll and sbt FileService/scalafmtAll produce no further diff.

Was this PR authored or co-authored using generative AI tooling?

Yes, partially. I (Suyash Jain) worked on this PR together with Claude Code as a pair-programming assistant. I reviewed the final diff and ran the unit and Testcontainers-based integration suites locally before opening the PR.

Generated-by: Claude Code (Claude Opus 4.7)

@github-actions github-actions Bot added fix platform Non-amber Scala service paths labels Jun 10, 2026
@codecov-commenter

codecov-commenter commented Jun 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.65217% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 52.63%. Comparing base (539a685) to head (8f4eb4a).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...e/texera/service/util/LakeFSExceptionHandler.scala 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5607      +/-   ##
============================================
+ Coverage     52.45%   52.63%   +0.17%     
- Complexity     2485     2496      +11     
============================================
  Files          1071     1071              
  Lines         41366    41376      +10     
  Branches       4442     4445       +3     
============================================
+ Hits          21698    21777      +79     
+ Misses        18399    18320      -79     
- Partials       1269     1279      +10     
Flag Coverage Δ *Carryforward flag
access-control-service 64.61% <ø> (ø)
agent-service 33.76% <ø> (ø) Carriedforward from 539a685
amber 53.35% <ø> (ø) Carriedforward from 539a685
computing-unit-managing-service 1.65% <ø> (ø)
config-service 58.57% <ø> (+1.85%) ⬆️
file-service 57.06% <95.65%> (+18.84%) ⬆️
frontend 47.03% <ø> (ø) Carriedforward from 539a685
pyamber 90.72% <ø> (ø) Carriedforward from 539a685
python 90.75% <ø> (ø) Carriedforward from 539a685
workflow-compiling-service 58.69% <ø> (ø)

*This pull request uses carry forward flags. 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:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@xuang7 xuang7 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.

Overall, this PR looks good to me. Could you help take another look? Thanks. @aicam

@xuang7
xuang7 requested a review from aicam June 10, 2026 21:43

@aicam aicam 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.

LGTM, @suyashj1231 did you test normal features on local development? like upload/download/use dataset in workflow?

@aicam
aicam added this pull request to the merge queue Jun 10, 2026
@aicam
aicam removed this pull request from the merge queue due to a manual request Jun 10, 2026
@suyashj1231

suyashj1231 commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @aicam , yes tested it locally to be sure. Ran the file-service from this branch inside the full single-node docker stack (everything else same), then just used the app normally in the browser:

Workflow:

  • created a dataset + uploaded a csv = multipart upload went through fine, committed as v1, file renders in the viewer
  • downloaded the single file and the version zip = both match the original exactly
  • pointed a CSV File Scan operator at the dataset file and ran the workflow = completed, all 3 rows came through

also tried hitting a missing file and got a clean 404 with the new "LakeFS resource not found" message instead of a raw 500, so the handler is doing its thing outside the failure-injection tests too.

08-dataset-created 11-version-created 22-file-picked 42-run-done

@aicam

aicam commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Hi @aicam , yes tested it locally to be sure. Ran the file-service from this branch inside the full single-node docker stack (everything else same), then just used the app normally in the browser:

Workflow:

  • created a dataset + uploaded a csv = multipart upload went through fine, committed as v1, file renders in the viewer
  • downloaded the single file and the version zip = both match the original exactly
  • pointed a CSV File Scan operator at the dataset file and ran the workflow = completed, all 3 rows came through

also tried hitting a missing file and got a clean 404 with the new "LakeFS resource not found" message instead of a raw 500, so the handler is doing its thing outside the failure-injection tests too.

08-dataset-created 11-version-created 22-file-picked 42-run-done

Thanks

@aicam
aicam added this pull request to the merge queue Jun 10, 2026
@Yicong-Huang
Yicong-Huang removed this pull request from the merge queue due to a manual request Jun 10, 2026

@Yicong-Huang Yicong-Huang 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.

Hi @suyashj1231 could you please add more tests to make coverage happy? The current coverage is too low. See #5607 (comment)

…points

The patch-coverage gaps in apache#5607 were concentrated in four endpoints the
suite never called: getDataset (repository size), uploadOneFileToDataset,
versionZip, and presign-download. Add happy-path and LakeFS
failure-injection tests for each, plus a response-body case for
LakeFSExceptionHandler.

uploadOneFileToDataset was previously untestable: MockLakeFS hardcoded
the LakeFS pre-signed endpoint to localhost:9000 while MinIO's host port
was dynamically mapped, so presigned part uploads could never reach
MinIO. Reserve a free host port, pin MinIO's 9000 to it, and point the
pre-signed endpoint at the same port.
@suyashj1231

suyashj1231 commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Added tests to cover the missing lines. While doing this I found uploadOneFileToDataset was actually untestable before, the test setup pointed LakeFS's presigned URLs at the wrong MinIO port, so I fixed that too.

@xuang7 xuang7 added the release/v1.2 back porting to release/v1.2 label Jun 12, 2026

@Yicong-Huang Yicong-Huang 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.

LGTM, thanks.

@Yicong-Huang
Yicong-Huang added this pull request to the merge queue Jun 12, 2026
Merged via the queue into apache:main with commit 7b1c8dc Jun 12, 2026
45 checks passed
Yicong-Huang pushed a commit that referenced this pull request Jun 12, 2026
### What changes were proposed in this PR?

#4177 introduced `LakeFSExceptionHandler.withLakeFSErrorHandling`, but
only the multipart-upload and dataset-version paths used it. The
remaining LakeFS call sites in `DatasetResource` either leaked raw
`io.lakefs.clients.sdk.ApiException` to Dropwizard (an opaque 500 for
the frontend) or caught `Exception` and rewrapped it as a generic 500,
discarding the real LakeFS status code (401/403/404/409/...).

```
Before:  LakeFS 404  ->  raw ApiException / catch(Exception)  ->  500 "Failed to ..."
After:   LakeFS 404  ->  withLakeFSErrorHandling              ->  404 "Error while deleting file 'a.csv' ...: LakeFS resource not found. ..."
```

Changes:

| Change | Where |
| --- | --- |
| New overload `withLakeFSErrorHandling(operation: String)(call)` that
prefixes the user-visible message with the failed operation |
`LakeFSExceptionHandler.scala` |
| 8 bare LakeFS calls now wrapped (size lookup, version listing, zip
download, presigned URLs, cover image) | `DatasetResource.scala` |
| 5 `catch Exception -> generic 500` blocks now use the handler;
compensation logic (DB rollback on failed repo init, multipart abort) is
preserved, and the abort-on-failure cleanup no longer masks the original
error | `DatasetResource.scala` |

Intentionally unchanged: best-effort cleanup sites that deliberately
swallow errors, the per-dataset skip in `listDatasets`, and the
`FileService` startup health check (failing fast at boot is correct
there).

### Any related issues, documentation, discussions?

Closes #4176

### How was this PR tested?

New `LakeFSExceptionHandlerSpec` (7 unit cases): status-code mapping
(400/401/403/404/409/4xx/5xx/unknown), operation context included in the
frontend-visible message, success passthrough, and non-LakeFS exceptions
propagating untouched.

New integration case in `DatasetResourceSpec`: deleting a dataset whose
LakeFS repository does not exist now yields `NotFoundException` (404)
instead of a generic 500.

```
sbt "FileService/testOnly org.apache.texera.service.util.LakeFSExceptionHandlerSpec"
# Tests: succeeded 7, failed 0
sbt "FileService/testOnly org.apache.texera.service.resource.DatasetResourceSpec"
# Tests: succeeded 94, failed 0  (Testcontainers: LakeFS 1.51 + MinIO + Postgres)
```

`sbt FileService/scalafixAll` and `sbt FileService/scalafmtAll` produce
no further diff.

### Was this PR authored or co-authored using generative AI tooling?

Yes, partially. I (Suyash Jain) worked on this PR together with Claude
Code as a pair-programming assistant. I reviewed the final diff and ran
the unit and Testcontainers-based integration suites locally before
opening the PR.

(backported from commit 7b1c8dc)

Generated-by: Claude Code (Claude Opus 4.7)
@github-actions

Copy link
Copy Markdown
Contributor

Backport to release/v1.2 succeeded as 7780a56. Run

yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
…che#5607)

### What changes were proposed in this PR?

apache#4177 introduced `LakeFSExceptionHandler.withLakeFSErrorHandling`, but
only the multipart-upload and dataset-version paths used it. The
remaining LakeFS call sites in `DatasetResource` either leaked raw
`io.lakefs.clients.sdk.ApiException` to Dropwizard (an opaque 500 for
the frontend) or caught `Exception` and rewrapped it as a generic 500,
discarding the real LakeFS status code (401/403/404/409/...).

```
Before:  LakeFS 404  ->  raw ApiException / catch(Exception)  ->  500 "Failed to ..."
After:   LakeFS 404  ->  withLakeFSErrorHandling              ->  404 "Error while deleting file 'a.csv' ...: LakeFS resource not found. ..."
```

Changes:

| Change | Where |
| --- | --- |
| New overload `withLakeFSErrorHandling(operation: String)(call)` that
prefixes the user-visible message with the failed operation |
`LakeFSExceptionHandler.scala` |
| 8 bare LakeFS calls now wrapped (size lookup, version listing, zip
download, presigned URLs, cover image) | `DatasetResource.scala` |
| 5 `catch Exception -> generic 500` blocks now use the handler;
compensation logic (DB rollback on failed repo init, multipart abort) is
preserved, and the abort-on-failure cleanup no longer masks the original
error | `DatasetResource.scala` |

Intentionally unchanged: best-effort cleanup sites that deliberately
swallow errors, the per-dataset skip in `listDatasets`, and the
`FileService` startup health check (failing fast at boot is correct
there).

### Any related issues, documentation, discussions?

Closes apache#4176

### How was this PR tested?

New `LakeFSExceptionHandlerSpec` (7 unit cases): status-code mapping
(400/401/403/404/409/4xx/5xx/unknown), operation context included in the
frontend-visible message, success passthrough, and non-LakeFS exceptions
propagating untouched.

New integration case in `DatasetResourceSpec`: deleting a dataset whose
LakeFS repository does not exist now yields `NotFoundException` (404)
instead of a generic 500.

```
sbt "FileService/testOnly org.apache.texera.service.util.LakeFSExceptionHandlerSpec"
# Tests: succeeded 7, failed 0
sbt "FileService/testOnly org.apache.texera.service.resource.DatasetResourceSpec"
# Tests: succeeded 94, failed 0  (Testcontainers: LakeFS 1.51 + MinIO + Postgres)
```

`sbt FileService/scalafixAll` and `sbt FileService/scalafmtAll` produce
no further diff.

### Was this PR authored or co-authored using generative AI tooling?

Yes, partially. I (Suyash Jain) worked on this PR together with Claude
Code as a pair-programming assistant. I reviewed the final diff and ran
the unit and Testcontainers-based integration suites locally before
opening the PR.

Generated-by: Claude Code (Claude Opus 4.7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix platform Non-amber Scala service paths release/v1.2 back porting to release/v1.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve LakeFS error handling with centralized exception wrapper

5 participants