beloglazov / couchdb-scala

A purely functional Scala client for CouchDB
Apache License 2.0
65 stars 19 forks source link

Missing uuid key on status endpoint (unsupported couchdb version?) #76

Open giftig opened 6 years ago

giftig commented 6 years ago

I don't see a stated couchdb version supported for this library so I'm not sure if I'm simply using a version for which this library wasn't designed, but I just tried playing with it for the first time and got this exception:

upickle.Invalid$Data: Key Missing: uuid (data: Obj(ArrayBuffer((couchdb,Str(Welcome)), (version,Str(2.0.0)), (vendor,Obj(ArrayBuffer((name,Str(The Apache Software Foundation))))))))                                           
        at upickle.GeneratedUtil$class.mapToArray(GeneratedUtil.scala:45)                                       
        at upickle.default$.mapToArray(Api.scala:25)                                                            
        at upickle.Implicits$$anonfun$CaseR$1.applyOrElse(Implicits.scala:83)                                   
        at upickle.Implicits$$anonfun$CaseR$1.applyOrElse(Implicits.scala:82)                                   
        at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:171)                                  
        at upickle.Implicits$Internal$$anon$1.apply(Implicits.scala:53)                                         
        at upickle.Implicits$Internal$$anon$1.apply(Implicits.scala:50)                                         
        at upickle.Types$Reader$$anonfun$read$1.applyOrElse(Types.scala:93)                                     
        ...

It's expecting a uuid field in the couchdb response, but the / endpoint on this version of couchdb isn't providing one. You can see the full details of the couchdb version in the stack trace there, but for easier reading:

$ curl -s localhost:5984 | python -mjson.tool
{
    "couchdb": "Welcome",
    "vendor": {
        "name": "The Apache Software Foundation"
    },
    "version": "2.0.0"
}
giftig commented 6 years ago

FWIW I've continued using the library against the same version of couchdb and so far found no issues, so it looks like the potentially absent uuid is a singular oversight.

giftig commented 5 years ago

@beloglazov Thanks for reminding me about this; I just saw your message from a couple of weeks ago on another issue I raised, and had a crack at addressing this one as it's the most straightforward. Unfortunately, it looks like your tests are quite tightly bound to wording in old versions of couchdb though, so while it was trivial to fix this, running the tests against the latest couchdb shows a lot of problems because of some changed error messages:

[info] User interface
[error]   x Get info about the DB instance
[error]    '-\/(upickle.Invalid$Data: Key Missing: uuid (data: {
[error]        "couchdb": "Welcome",
[error]        "version": "2.0.0",
[error]        "vendor": {
[error]            "name": "The Apache Software Foundation"
[error]        }
[error]    }))' is not \/- (CouchDbSpecification.scala:47)
[info] 
[error]   x Create and query 2 DBs
[error]    'Database does not exist.' is not equal to 'missing' [CouchDbSpec.scala:42]
[error]    'Database does not exist.' is not equal to 'missing' [CouchDbSpec.scala:42] (CouchDbSpec.scala:42)
[error] Actual:   Database does not exist.
[error] Expected: missing
[error] Failed: Total 86, Failed 27, Errors 0, Passed 59
[error] Failed tests:

I can submit a PR with my change, but since it's only useful for a version of couchdb where your tests are widely failing, I think that's a bigger problem. Largely the errors are to do with error messages changing, so I'd suggest you try to eliminate some of the dependence on precise wording (usually a good idea for any test to avoid relying on information aimed for humans to read), however it looks like some other API details may have changed, so the library probably needs an update in some areas beside this optional uuid thing:

[error]     x fail if one or more elements is missing a Rev
[error]      '-\/(upickle.Invalid$Data: Key Missing: offset (data: {
...
giftig commented 5 years ago

I've created #82 to track this separately so that it doesn't get confusing.