bytes icon indicating copy to clipboard operation
bytes copied to clipboard

Unclear documentation for Decode.decode

Open danfishgold opened this issue 5 years ago • 4 comments

The current function documentation is:

decode : Decoder a -> Bytes -> Maybe a

The Decoder specifies exactly how this should happen. This process may fail if the sequence of bytes is corrupted or unexpected somehow. The examples above show a case where there are not enough bytes.

What does "corrupted sequence of bytes" mean here? signedInt8 should work on any Bytes given to it. Is there a case where using it in decode yields Nothing?

If there is, I think a more explicit warning would help (and ideally some links about possible issues). If there isn't, the documentation should say that the only reason for decoding to fail is by passing the decoder a sequence of bytes that it is unable to parse.

danfishgold avatar Aug 24 '19 14:08 danfishgold

@danfishgold not sure if I understand, if one has a decoder that expects 3 bytes and only 2 are given, decode will return Nothing. I guess corrupted simply means the input does not conform to ones expectations possibly due to transport issues.

As a user of the library I don't find in this specific case a source of confusion

I was thinking that it would be useful that decode would return a Result then the implementer of a library could explain what went wrong in the decoding, but I think is doable by having decoders that decode to a result.

maca avatar Sep 08 '19 13:09 maca

@maca

I guess corrupted simply means the input does not conform to ones expectations possibly due to transport issues.

That's what I want to find out: if I know what goes into the decode function and I know the decoder can handle it, is there still a case where decode would return Nothing?

danfishgold avatar Nov 04 '19 22:11 danfishgold

@danfishgold There are many instances where the decoder wont be able to handle the input. My specific scenario is a PNG decode library I am working on, if the user uploads a file that is not a PNG, the decoder will return Nothing.

maca avatar Nov 04 '19 23:11 maca

I'm talking about decoders that always succeed (like signedInt8): would they ever return Nothing? The answer to that question is unclear in the docs

danfishgold avatar Nov 11 '19 08:11 danfishgold