aptly icon indicating copy to clipboard operation
aptly copied to clipboard

Adding malformed package via API does not lead to error code, only warning in reply.

Open iliis opened this issue 3 years ago • 0 comments

I'm not sure this is really a bug, but it might be helpful to others that run into the same issue:

Detailed Description

I have a debian package with malformed content in the control file [1] and when I try to add it to a local repository via the REST API the server reports a 200 OK status:

$ curl -X POST --write-out '\n\nstatus: %{http_code}\n' http://myserver/api/repos/myrepo/file/myrepo/my_package.deb
{"FailedFiles":["/data/aptly/upload/myrepo/my_package.deb"],"Report":{"Warnings":["Unable to read file /data/aptly/upload/myrepo/my_package.deb: malformed stanza syntax"],"Added":[],"Removed":[]}}

status: 200

Doing the same via the command line interface leads to the following error message:

$ aptly repo add myrepo my_package.deb`
Loading packages...
[!] Unable to read file my_package.deb: malformed stanza syntax
[!] Some files were skipped due to errors:
  my_package.deb
ERROR: some files failed to be added

The request failed (my package was not added), so I would expect the status code to reflect this.

Context

I'm using aptly in a CI pipeline. Checking the HTTP reply status code is built in and trivial, parsing the returned JSON is more cumbersome (although possible in my case) and it's not obvious that this is required to make sure the step succeeded.

Possible Implementation

How about returning 409 or something if one or more of the files could not be added?

My Environment

Ubuntu 20.04, aptly 1.4.0


[1] The multi-line description field in the control file was missing spaces at the front of the lines, due to an older version of CPackDeb which doesn't handle this automatically.

iliis avatar Jan 19 '22 17:01 iliis