# YZ1 (Expected simple string or bulk string, got NIL)

**URL:** <https://forum.codecrafters.io/t/yz1-expected-simple-string-or-bulk-string-got-nil/2051>\
**Category:** Challenges\
**Tags:** challenge:redis\
**Created:** [September 29, 2024, 4:44am UTC](https://forum.codecrafters.io/t/yz1-expected-simple-string-or-bulk-string-got-nil/2051 "2024-09-29T04:44:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![softwarelifter](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/softwarelifter/32/1917_2.png) [@softwarelifter](https://forum.codecrafters.io/u/softwarelifter)\
**Post date:** [September 29, 2024, 4:44am UTC](https://forum.codecrafters.io/t/yz1-expected-simple-string-or-bulk-string-got-nil/2051/1 "2024-09-29T04:44:03Z")

</div>

I’m stuck on Stage #YZ1

I’ve tried …

Here are my logs:

```auto
response "$-1\r\n"
[tester::#LA7] Received bytes: "$-1\r\n"
[tester::#LA7] Received RESP null bulk string: "$-1\r\n"
[tester::#LA7] Expected simple string or bulk string, got NIL
[tester::#LA7] Test failed
[tester::#LA7] Terminating program
[tester::#LA7] Program terminated successfully

```

And here’s a snippet of my code:

```typescript

const delimiter = '\r\n'
export class RespSerializer {
    public static serialize(data: IRespData | null) {
        if (!data) {
            return RespSerializer.serializeBulkString(null)
        }
        console.log("data", data)
        switch (data.type) {
            case RespDataType.ArrayType:
                return RespSerializer.serializeArrays(data.value as IRespData[])
            case RespDataType.BulkString:
                return RespSerializer.serializeBulkString(data.value as string)
            case RespDataType.SimpleString:
                return RespSerializer.serializeSimpleString(data.value as string)
            case RespDataType.Integer:
                return RespSerializer.serializeInteger(data.value as number)
            case RespDataType.Error:
                return RespSerializer.serializeError(data.value as string)
            default:
            //handle default
        }
    }

    public static serializeSimpleString(str: string) {
        return `${RespDataType.SimpleString}${str}${delimiter}`
    }
    public static serializeInteger(num: number) {
        return `${RespDataType.Integer}${num}${delimiter}`
    }
    public static serializeError(str: string) {
        return `${RespDataType.Error}${str}${delimiter}`
    }
    public static serializeBulkString(str: string | null) {
        if (str === null) {
            return `${RespDataType.BulkString}${-1}${delimiter}`
        }
        return `${RespDataType.BulkString}${str.length}${delimiter}${str}${delimiter}`
    }
    public static serializeArrays(data: IRespData[]) {
        let res = ""
        data.map((item) => {
            const itemStr = this.serialize(item)
            res += itemStr
        })
        return `${RespDataType.ArrayType}${data.length}${delimiter}${res}`
    }
}
public static serializeBulkString(str: string | null) {
        if (str === null) {
            return `${RespDataType.BulkString}${-1}${delimiter}`
        }
        return `${RespDataType.BulkString}${str.length}${delimiter}${str}${delimiter}`
    }

```

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [September 29, 2024, 1:41pm UTC](https://forum.codecrafters.io/t/yz1-expected-simple-string-or-bulk-string-got-nil/2051/2 "2024-09-29T13:41:26Z")

</div>

@softwarelifter Your response was correct for Stage #YZ1.

The error occurred when our tester tried to test the previous stage ( **Implement the SET & GET commands #la7** ) after your code had passed #YZ1.

It’s common for changes made in later stages to inadvertently break earlier ones. You can install our [CLI](https://docs.codecrafters.io/cli/installation) and test against previous stages first by running this command:

```auto
codecrafters test --previous

```

(There are actually several earlier stages that are broken, not just #la7.)

---

<div class="post-metadata">

**Author:** ![softwarelifter](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/softwarelifter/32/1917_2.png) [@softwarelifter](https://forum.codecrafters.io/u/softwarelifter)\
**Post date:** [September 30, 2024, 1:22am UTC](https://forum.codecrafters.io/t/yz1-expected-simple-string-or-bulk-string-got-nil/2051/3 "2024-09-30T01:22:08Z")

</div>

@andy1li thanks that was helpful, it’s working now

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [October 5, 2024, 1:22am UTC](https://forum.codecrafters.io/t/yz1-expected-simple-string-or-bulk-string-got-nil/2051/4 "2024-10-05T01:22:13Z")

</div>

Closed on October 5, 2024, 1:22am UTC

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
