Skip to content

feat: add centralized LakeFS error handling for multipart upload and dataset version operations - #4177

Merged
aicam merged 3 commits into
apache:mainfrom
xuang7:feat/handle-lakefs-exception
Jan 27, 2026
Merged

aicam merged 3 commits into
apache:mainfrom
xuang7:feat/handle-lakefs-exception

Conversation

@xuang7

@xuang7 xuang7 commented Jan 24, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

This PR adds centralized error handling for LakeFS API calls in DatasetResource, covering multipart upload and dataset version operations. This improves error visibility by returning meaningful HTTP status codes and error messages to the frontend. Currently, the wrapper is applied to these specific calls only, and has not yet been applied to all LakeFS calls.

Changes

  • Converts LakeFS ApiException to HTTP exception (400, 401, 403, 404, 409, 410, 412, 416, 420, 500)
  • Applied to createDatasetVersion, getDatasetDiff, initMultipartUpload, finishMultipartUpload, abortMultipartUpload

Any related issues, documentation, discussions?

Related to #4176

How was this PR tested?

  • Passed existing automated tests
  • Added test case in DatasetResourceSpec for error message response and 500 internal error handling
  • Manual testing of multipart upload error flows

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

Generated-by: Claude (Anthropic)

@chenlica

Copy link
Copy Markdown
Contributor

@carloea2 Please review it first before @aicam does it.

Comment on lines +431 to +437
val commit = withLakeFSErrorHandling {
LakeFSStorageClient.createCommit(
repoName = repositoryName,
branch = "main",
commitMessage = s"Created dataset version: $newVersionName"
)
}

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.

@xuang7 There is another approach with scala implicit, it will look like the next code snippet, in your preference, is this cleaner?

val commit =
  LakeFSStorageClient.safeCall(_.createCommit(
    repoName = repositoryName,
    branch = "main",
    commitMessage = s"Created dataset version: $newVersionName"
  ))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. I currently centralized the LakeFS exception→HTTP mapping in the file-service (LakeFSExceptionHandler). The safeCall approach also looks clean and would centralize handling at the storage layer near LakeFSStorageClient. Would you recommend switching to LakeFSStorageClient.safeCall(...) so all callers share the same handler?

@carloea2 carloea2 Jan 26, 2026 •

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.

We can keep this approach for now.

It would be good to open a discussion, and would be good if @Ma77Ball can give his input since he is working in logging. Here is the things to discuss later:

I think this PR is really about how we want error handling to work across the services calls (LakeFS now, others later): do we force callers to deal with failures, or do we centralize + make it easy/consistent.

Option 1: change defs and force handling (typed)

Return Either[StorageError, A] (or F[Either[...]]). Caller can’t ignore it.

storage.commit(repo, branch, msg): Either[StorageError, CommitId]
storage.uploadPart(key, part, bytes): Either[StorageError, Unit]

// usage
storage.commit(repo, branch, msg).map(Ok(_)).leftMap(mapToHttp)

Pros: type-safe + enforced. Cons: signature churn + lots of callsite updates + need Error mapping.

Option 2: implicit + Dynamic .safe wrapper (ergonomic, but risky)

This option adds automatic logs
Nice callsite but reflection + weak typing (Any) + possible runtime method lookup issues. Notice this method does not require any changes to the def like commit, or uploadPart but it is optional to the caller to use .safe and

Changing the return type (2.1)

lakefs.safe.commit(repo, branch, msg)          // Either[Throwable, Any]
datasetResource.safe.uploadPart(key, part, bs) // Either[Throwable, Any]

Keeping the return type and throwing (2.2)

lakefs.safe.commit(repo, branch, msg)
datasetResource.safe.uploadPart(key, part, bs)

case 416 => new WebApplicationException(errorResponse(416))
case 420 => new WebApplicationException(errorResponse(420))
case _ => new InternalServerErrorException(errorResponse(500))
})

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.

Can the codes be extracted dynamically from code (Maybe from LakeFs) so for future changes from their side there is no need to maintain this piece of code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. For now we're using a small fallback map for the common LakeFS status codes, which are fairly stable. Please let me know if you’d recommend dynamically extracting codes from the ApiException instead.

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.

I think it will be good if possible, if not this approach is good enough. Thanks.

@carloea2

Copy link
Copy Markdown
Contributor

LGTM.

@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, I think it provides first hand experience and later we can improve it, currently I have no preference on options @carloea2 mentioned until we test this

@aicam
aicam enabled auto-merge (squash) January 26, 2026 19:45
@aicam
aicam merged commit 0aa4ad4 into apache:main Jan 27, 2026
11 of 24 checks passed
madisonmlin pushed a commit to madisonmlin/texera that referenced this pull request Mar 10, 2026
…dataset version operations (apache#4177)

<!--
Thanks for sending a pull request (PR)! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines:
[Contributing to
Texera](https://github.com/apache/texera/blob/main/CONTRIBUTING.md)
  2. Ensure you have added or run the appropriate tests for your PR
  3. If the PR is work in progress, mark it a draft on GitHub.
  4. Please write your PR title to summarize what this PR proposes, we 
    are following Conventional Commits style for PR titles as well.
  5. Be sure to keep the PR description updated to reflect all changes.
-->

### What changes were proposed in this PR?
<!--
Please clarify what changes you are proposing. The purpose of this
section
is to outline the changes. Here are some tips for you:
  1. If you propose a new API, clarify the use case for a new API.
  2. If you fix a bug, you can clarify why it is a bug.
  3. If it is a refactoring, clarify what has been changed.
  3. It would be helpful to include a before-and-after comparison using 
     screenshots or GIFs.
  4. Please consider writing useful notes for better and faster reviews.
-->
This PR adds centralized error handling for LakeFS API calls in
`DatasetResource`, covering multipart upload and dataset version
operations. This improves error visibility by returning meaningful HTTP
status codes and error messages to the frontend. Currently, the wrapper
is applied to these specific calls only, and has not yet been applied to
all LakeFS calls.

### Changes
- Converts LakeFS `ApiException` to HTTP exception (400, 401, 403, 404,
409, 410, 412, 416, 420, 500)
- Applied to `createDatasetVersion`, `getDatasetDiff`,
`initMultipartUpload`, `finishMultipartUpload`, `abortMultipartUpload`

### Any related issues, documentation, discussions?
<!--
Please use this section to link other resources if not mentioned
already.
1. If this PR fixes an issue, please include `Fixes apache#1234`, `Resolves
apache#1234`
or `Closes apache#1234`. If it is only related, simply mention the issue
number.
  2. If there is design documentation, please add the link.
  3. If there is a discussion in the mailing list, please add the link.
-->
Related to apache#4176

### How was this PR tested?
<!--
If tests were added, say they were added here. Or simply mention that if
the PR
is tested with existing test cases. Make sure to include/update test
cases that
check the changes thoroughly including negative and positive cases if
possible.
If it was tested in a way different from regular unit tests, please
clarify how
you tested step by step, ideally copy and paste-able, so that other
reviewers can
test and check, and descendants can verify in the future. If tests were
not added,
please describe why they were not added and/or why it was difficult to
add.
-->
- Passed existing automated tests
- Added test case in `DatasetResourceSpec` for error message response
and 500 internal error handling
- Manual testing of multipart upload error flows

### Was this PR authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this
PR,
please include the phrase: 'Generated-by: ' followed by the name of the
tool
and its version. If no, write 'No'. 
Please refer to the [ASF Generative Tooling
Guidance](https://www.apache.org/legal/generative-tooling.html) for
details.
-->
Generated-by: Claude (Anthropic)
SarahAsad23 pushed a commit to madisonmlin/texera that referenced this pull request May 20, 2026
…dataset version operations (apache#4177)

<!--
Thanks for sending a pull request (PR)! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines:
[Contributing to
Texera](https://github.com/apache/texera/blob/main/CONTRIBUTING.md)
  2. Ensure you have added or run the appropriate tests for your PR
  3. If the PR is work in progress, mark it a draft on GitHub.
  4. Please write your PR title to summarize what this PR proposes, we 
    are following Conventional Commits style for PR titles as well.
  5. Be sure to keep the PR description updated to reflect all changes.
-->

### What changes were proposed in this PR?
<!--
Please clarify what changes you are proposing. The purpose of this
section
is to outline the changes. Here are some tips for you:
  1. If you propose a new API, clarify the use case for a new API.
  2. If you fix a bug, you can clarify why it is a bug.
  3. If it is a refactoring, clarify what has been changed.
  3. It would be helpful to include a before-and-after comparison using 
     screenshots or GIFs.
  4. Please consider writing useful notes for better and faster reviews.
-->
This PR adds centralized error handling for LakeFS API calls in
`DatasetResource`, covering multipart upload and dataset version
operations. This improves error visibility by returning meaningful HTTP
status codes and error messages to the frontend. Currently, the wrapper
is applied to these specific calls only, and has not yet been applied to
all LakeFS calls.

### Changes
- Converts LakeFS `ApiException` to HTTP exception (400, 401, 403, 404,
409, 410, 412, 416, 420, 500)
- Applied to `createDatasetVersion`, `getDatasetDiff`,
`initMultipartUpload`, `finishMultipartUpload`, `abortMultipartUpload`

### Any related issues, documentation, discussions?
<!--
Please use this section to link other resources if not mentioned
already.
1. If this PR fixes an issue, please include `Fixes apache#1234`, `Resolves
apache#1234`
or `Closes apache#1234`. If it is only related, simply mention the issue
number.
  2. If there is design documentation, please add the link.
  3. If there is a discussion in the mailing list, please add the link.
-->
Related to apache#4176

### How was this PR tested?
<!--
If tests were added, say they were added here. Or simply mention that if
the PR
is tested with existing test cases. Make sure to include/update test
cases that
check the changes thoroughly including negative and positive cases if
possible.
If it was tested in a way different from regular unit tests, please
clarify how
you tested step by step, ideally copy and paste-able, so that other
reviewers can
test and check, and descendants can verify in the future. If tests were
not added,
please describe why they were not added and/or why it was difficult to
add.
-->
- Passed existing automated tests
- Added test case in `DatasetResourceSpec` for error message response
and 500 internal error handling
- Manual testing of multipart upload error flows

### Was this PR authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this
PR,
please include the phrase: 'Generated-by: ' followed by the name of the
tool
and its version. If no, write 'No'. 
Please refer to the [ASF Generative Tooling
Guidance](https://www.apache.org/legal/generative-tooling.html) for
details.
-->
Generated-by: Claude (Anthropic)
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)
Yicong-Huang pushed a commit to Ma77Ball/texera that referenced this pull request Jun 12, 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)
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
…dataset version operations (apache#4177)

<!--
Thanks for sending a pull request (PR)! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines:
[Contributing to
Texera](https://github.com/apache/texera/blob/main/CONTRIBUTING.md)
  2. Ensure you have added or run the appropriate tests for your PR
  3. If the PR is work in progress, mark it a draft on GitHub.
  4. Please write your PR title to summarize what this PR proposes, we 
    are following Conventional Commits style for PR titles as well.
  5. Be sure to keep the PR description updated to reflect all changes.
-->

### What changes were proposed in this PR?
<!--
Please clarify what changes you are proposing. The purpose of this
section
is to outline the changes. Here are some tips for you:
  1. If you propose a new API, clarify the use case for a new API.
  2. If you fix a bug, you can clarify why it is a bug.
  3. If it is a refactoring, clarify what has been changed.
  3. It would be helpful to include a before-and-after comparison using 
     screenshots or GIFs.
  4. Please consider writing useful notes for better and faster reviews.
-->
This PR adds centralized error handling for LakeFS API calls in
`DatasetResource`, covering multipart upload and dataset version
operations. This improves error visibility by returning meaningful HTTP
status codes and error messages to the frontend. Currently, the wrapper
is applied to these specific calls only, and has not yet been applied to
all LakeFS calls.

### Changes
- Converts LakeFS `ApiException` to HTTP exception (400, 401, 403, 404,
409, 410, 412, 416, 420, 500)
- Applied to `createDatasetVersion`, `getDatasetDiff`,
`initMultipartUpload`, `finishMultipartUpload`, `abortMultipartUpload`

### Any related issues, documentation, discussions?
<!--
Please use this section to link other resources if not mentioned
already.
1. If this PR fixes an issue, please include `Fixes apache#1234`, `Resolves
apache#1234`
or `Closes apache#1234`. If it is only related, simply mention the issue
number.
  2. If there is design documentation, please add the link.
  3. If there is a discussion in the mailing list, please add the link.
-->
Related to apache#4176

### How was this PR tested?
<!--
If tests were added, say they were added here. Or simply mention that if
the PR
is tested with existing test cases. Make sure to include/update test
cases that
check the changes thoroughly including negative and positive cases if
possible.
If it was tested in a way different from regular unit tests, please
clarify how
you tested step by step, ideally copy and paste-able, so that other
reviewers can
test and check, and descendants can verify in the future. If tests were
not added,
please describe why they were not added and/or why it was difficult to
add.
-->
- Passed existing automated tests
- Added test case in `DatasetResourceSpec` for error message response
and 500 internal error handling
- Manual testing of multipart upload error flows

### Was this PR authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this
PR,
please include the phrase: 'Generated-by: ' followed by the name of the
tool
and its version. If no, write 'No'. 
Please refer to the [ASF Generative Tooling
Guidance](https://www.apache.org/legal/generative-tooling.html) for
details.
-->
Generated-by: Claude (Anthropic)
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)
@xuang7
xuang7 deleted the feat/handle-lakefs-exception branch July 1, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants