tc39/proposal-arraybuffer-base64

The order of validation / errors

zloirock opened this issue · 2 comments

Let's take a look, for example, at the errors order in Uint8Array.fromBase64 at string parsing:

image

Sure, all of those errors are SyntaxError, but for better debugging, it seems in implementations they will have different error messages. And here we have 2 problems:

  • It will cause problems for parsing in 1 pass
  • The order of error is strange - for example, in case of the string with wrong length and symbols with another encoding (+-\_), with base64 encoding we will have the error with length, with base64url - with wrong symbols

Because the spec does not specify messages, from the point of view of the spec any choice of ordering is legal. There's a NOTE about this in the spec:

  1. NOTE: The order of validation and decoding in the algorithm below is not observable. Implementations are encouraged to perform them in whatever order is most efficient, possibly interleaving validation and stripping whitespace with decoding, as long as the behaviour is observably equivalent.

Ok, let it be -) I thought that this note did not apply to the entire subsequent algorithm.