Repository navigation
Description
As it's currently designed, the batch api is very flexible. It receives a list of objects, and returns details on each object with either an upload or download link relation. This works great for the happy path, but not some potential failure cases:
- Client requests 5 objects to download. Server responds with all "download" relations for all 5 objects.
- Client requests 5 objects to upload. Server responds with either "download" (no need to re-upload existing objects) and "upload" relations for all 5 objects.
- Client requests 5 objects to download. Server responds with "download" relations for 4, but has no record of a fifth.
- Client requests 5 objects to upload, but without write access to the repository. Server responds with an empty array or "download" relations for existing objects.
- Client requests 5 objects to upload, but some or all of the objects fail some server side validation. Maybe some files are too large, the OID is the wrong format, the repo's usage quota is exceeded, etc.
For downloads: I'd like Git LFS to tolerate missing objects. It shouldn't bail out of a longer operation. It should download what it can, and write that some objects weren't found.
Uploads are trickier. There's no point even returning 200 if the user doesn't have write access to the repository. But currently there's no way for the server to know whether the client wants to upload or download the objects.
Proposal
I'd like to update the batch API to send and receive a bit more context. The client can send an operation key that specifies whether this request is for an upload or a download. Servers respond with an error property if it can't satisfy the operation for any given object. The error message will simply be written to STDERR without being parsed in any way by the client.
> POST https://git-lfs-server.com/objects/batch HTTP/1.1
> Accept: application/vnd.git-lfs+json
> Content-Type: application/vnd.git-lfs+json
> Authorization: Basic ... (if authentication is needed)
>
> {
> "operation": "upload",
> "objects": [
> {
> "oid": "1111111",
> "size": 123
> },
> {
> "oid": "2222222",
> "size": 123
> }
> ]
> }
>
< HTTP/1.1 200 Accepted
< Content-Type: application/vnd.git-lfs+json
<
< {
< "objects": [
< {
< "oid": "1111111",
< "_links": {
< "upload": {
< "href": "https://some-upload.com",
< "header": {
< "Key": "value"
< }
< }
< }
> },
< {
< "oid": "2222222",
< "error": "the file is too large"
> }
< ]
< }
This should work fine with all of the scenarios above:
- Client requests 5 objects to download. Server responds with all "download" relations for all 5 objects.
- Client requests 5 objects to upload. Server responds "upload" relations for objects that don't exist on the server yet. Client ignores the missing objects in the response, assuming they already exist on the server.
- Client requests 5 objects to download. Server responds with "download" relations for 4, but has no record of a fifth. Client downloads the 4 objects, and writes the fifth object's
errorto STDERR. - Client requests 5 objects to upload, but without write access to the repository. Server responds 403.
- Client requests 5 objects to upload, but some or all of the objects fail some server side validation. Server responds with "upload" link relations for the valid objects, and
errorproperties for the others. Client uploads what it can, but prints anyerrormessages to STDERR.
Does the idea sound good? Am I missing anything?
Activity
rubyist commentedon Jun 18, 2015
👍 I think this is good, adding an operation makes total sense. It also leaves open possible extensions where we might really be asking about both downloads and uploads at once.
For downloads we're still relying on smudge outside of the fetch command, so there is no longer operation, they're all independent. For the fetch command (and possible future post-checkout triggers), the current batch code does not bail out for any missing objects or errors. All errors are collected and displayed at the end. Same thing happens for uploads. That type of client behavior, though, is outside of the API spec, IMO, those are client implementation details.
technoweenie commentedon Jun 18, 2015
Sounds like the only thing missing is checking for and printing the error string to STDERR or whatever. 👍
michael-k commentedon Jun 19, 2015
We shouldn't forget the use case where a client (not necessarily this one) can do something about some errors. Therefore we shouldn't forget machine readability. Maybe in form of error codes.
Very simple use case: client wants to link to an error specific help page.
technoweenie commentedon Jun 19, 2015
I thought about that, but wasn't sure what clients could even do about server side issues. Though we could start with a simple "fatal" error code, and define specific ones (
too_large?) as we think of them.How should it be represented in the JSON?
I tend to prefer nested objects in JSON over multiple attributes with an
error_prefix. For comparison, here's how the GitHub API returns validation errors:rubyist commentedon Jun 19, 2015
nested version has my 👍
michael-k commentedon Jun 20, 2015
nested