Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong keyPath message on DecodeError.TypeMismatch #120

Closed
toshi0383 opened this issue Apr 18, 2016 · 2 comments
Closed

Wrong keyPath message on DecodeError.TypeMismatch #120

toshi0383 opened this issue Apr 18, 2016 · 2 comments

Comments

@toshi0383
Copy link

decodeValue reports the wrong keyPath.
The TypeMismatch error below should be like this

TypeMismatch(expected: Int, actual: String, keyPath: KeyPath(["displayType"]))

, instead of this

TypeMismatch(expected: Int, actual: Optional(), keyPath: KeyPath(["dialog"]))

Test Code

let json = loadJson("videoFileList_error.json") as! JSON
let _: ErrorObject.Data = try! decodeValue(json["error"]!["data"]!)
struct ErrorObject: Decodable {
    let code: Int
    let message: String
    let data: Data?
    struct Data: Decodable {
        let dialog: Dialog?
        let url: String?
        struct Dialog: Decodable {
            let title: String?
            let message: String?
            let displayType: Int?
{
    "result": null,
    "error": {
        "code": 110,
        "message": "",
        "data": {
            "dialog": {
                "title": "",
                "message": "",
                "displayType": ""  // This causes TypeMismatch because it's String instead of expected Int?.
            },
            "url": null
        }
    },
    "id": "1",
    "jsonrpc": "2.0"
}
@ikesyo
Copy link
Owner

ikesyo commented Apr 19, 2016

Thank you for the report!

actual: String

This is not the expected output. The “actual” part is an actual value, not a type of the value. In this case, Optional() is really Optional.Some("").

keyPath part should be a bug. I'll fix it.

@toshi0383
Copy link
Author

Oh I see that now. Thanks for response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants