Skip to content
This repository

sprintf error should be more awesome #759

Closed
Benabik opened this Issue · 3 comments

2 participants

Brian Gernhardt Andrew Whitworth
Brian Gernhardt
Collaborator

Currently, sprintf str, "%;", [] throws the following exception: ';' is not a valid sprintf format. It would be more clear if it displayed the entire format there, including the %.

First thought on implementation: keep an index for the % character and then substr between there and the current position before throwing the exception.

Andrew Whitworth
Owner

I've started a new branch, whiteknight/sprintf_cleanup, to work on several issues related to the sprintf code, including this ticket. I will post updates as the work progresses.

Andrew Whitworth Whiteknight referenced this issue from a commit
Andrew Whitworth A few small code cleanups. Fix t/op/sprintf.t, since it is wonderfull…
…y matching on the exact text of the exception message, which is changing for GH #759
3fc0977
Andrew Whitworth
Owner

@benabik The error message has been updated to say:

"'%c' is not valid in sprintf format sequence '%Ss'"

Where the second parameter is the text of the format sequence so far. Once the state machine finds one incorrect character it can't keep going to find the complete intended format, so this is the best we can do. If this is acceptable to you, I'll merge my branch to master and close this ticket.

Andrew Whitworth
Owner

I have just merged this branch to master. The error message is improved as best as I can make it. I'm closing this ticket.

Andrew Whitworth Whiteknight closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.