greghendershott/aws

aws/sns publish contract inconsistent with code

nxg opened this issue · 4 comments

nxg commented

The documentation has:

(publish topic-arn                 
     message                   
     #:subject subject         
     #:json? json?)    -> void?
  topic-arn : string?              
  message : string?                
  subject : ""                     
  json? : #f  

however the actual contract is:

((string? string?)
   (#:subject (or/c #f string?) #:json? boolean?)
   . ->* . any)

(I'm raising an issue rather than suggesting a patch, because I'm not confident I know what the return value ought to be).

IIUC there are two discrepancies:

  1. Return value. This is actually intentional. The doc says void? meaning, don't rely on the value. The code uses any because that's faster -- faster than void? (and also faster than any/c for example). I've seen this advice on the mailing list and in other Racket code.
  2. Although you mentioned the return value, I notice that docs for subject and json? are goofy. It looks like in the Scribble I did [#:kw name default] instead of [#:kw name contract default], so I should fix that.

Well, as I review the code it looks like the contract for subject is too permissive. I don't think #f will work. Instead of (or/c #f string?) it should be string?.

nxg commented

Sounds good. I noticed this when I did require/typed on aws/sns, and Racket complained that the type I deduced from the docs didn't match the contract. I just put (-> ... Any) in the type and Racket was happy.

I'll remember that about void?/any contracts -- thanks!

Ah, yes, Typed Racket is great at flushing out equivocations like that.

By the way, this aws package is one of my earliest for Racket, and waaaaaay predates my experience using Typed Racket. Otherwise I probably would have provided require/typd wrappers in a typed subdir -- or perhaps even done it all directly in Typed Racket.

Alas it turns out I'm not actively using aws, lately, and don't really have time to do any of that in the foreseeable future. On the off chance you'd want to contribute any I'd be grateful -- but of course I realize that's a lot of work, so no worries if you can't.