Skip to content

Commit

Permalink
Merge pull request #139 from codecrafters-io/clarify-resp-value
Browse files Browse the repository at this point in the history
Refactor RESP to RESP2 error messages and tests
  • Loading branch information
rohitpaulk authored Apr 29, 2024
2 parents 7cd18f7 + 674306f commit 46691d3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions internal/resp/decoder/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func doDecodeValue(reader *bytes.Reader) (resp_value.Value, error) {
if err == io.EOF {
return resp_value.Value{}, IncompleteInputError{
Reader: reader,
Message: "Expected start of a new RESP value (either +, -, :, $ or *)",
Message: "Expected start of a new RESP2 value (either +, -, :, $ or *)",
}
}

Expand All @@ -44,7 +44,7 @@ func doDecodeValue(reader *bytes.Reader) (resp_value.Value, error) {

return resp_value.Value{}, InvalidInputError{
Reader: reader,
Message: fmt.Sprintf("%q is not a valid start of a RESP value (expected +, -, :, $ or *)", string(firstByte)),
Message: fmt.Sprintf("%q is not a valid start of a RESP2 value (expected +, -, :, $ or *)", string(firstByte)),
}
}
}
5 changes: 2 additions & 3 deletions internal/resp/decoder/decode_error_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
error: |
Received: "" (no content received)
^ error
Error: Expected start of a new RESP value (either +, -, :, $ or *)
Error: Expected start of a new RESP2 value (either +, -, :, $ or *)
- input: "K"
error: |
Received: "K"
^ error
Error: "K" is not a valid start of a RESP value (expected +, -, :, $ or *)
Error: "K" is not a valid start of a RESP2 value (expected +, -, :, $ or *)
# Simple Strings

Expand Down Expand Up @@ -102,7 +102,6 @@
^ error
Error: Invalid integer: "foo", expected a number
# Arrays

# - input: "*abc"
Expand Down
2 changes: 1 addition & 1 deletion internal/test_helpers/fixtures/ping-pong/eof
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Debug = true
[stage-2] Sent bytes: "*1\r\n$4\r\nPING\r\n"
[stage-2] Received: "" (no content received)
[stage-2]  ^ error
[stage-2] Error: Expected start of a new RESP value (either +, -, :, $ or *)
[stage-2] Error: Expected start of a new RESP2 value (either +, -, :, $ or *)
[stage-2] Test failed
[stage-2] Terminating program
[stage-2] Program terminated successfully

0 comments on commit 46691d3

Please sign in to comment.