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

dump failed if there is a nil value #232

Closed
Whirlwind opened this issue Nov 20, 2019 · 3 comments · Fixed by #248
Closed

dump failed if there is a nil value #232

Whirlwind opened this issue Nov 20, 2019 · 3 comments · Fixed by #248

Comments

@Whirlwind
Copy link

Whirlwind commented Nov 20, 2019

image
I am using Swift 5.1 and Xcode 11.2.1.

I try to debug the Yams, and it throw a error:

private func represent(_ value: Any) throws -> Node {
    if let string = value as? String {
        return Node(string)
    } else if let representable = value as? NodeRepresentable {
        return try representable.represented()
    }
    throw YamlError.representer(problem: "Failed to represent \(value)")  // -> print "Failed to represent nil"
}

extension Optional: NodeRepresentable {
    public func represented() throws -> Node {
        switch self {
        case let .some(wrapped):
            return try represent(wrapped)  // <-- The ALIAS's value hit this case, but it is nil. As it is a .some<nil>
        case .none:
            return Node("null", Tag(.null))
        }
    }
}

Is it a bug?

@Whirlwind
Copy link
Author

Whirlwind commented Nov 20, 2019

I try to fix it:

extension NSNull: NodeRepresentable {
    /// This value's `Node.scalar` representation.
    public func represented() -> Node {
        return Node("", Tag(.null))
    }
}

It works.

@jpsim jpsim mentioned this issue Nov 27, 2019
2 tasks
@jpsim
Copy link
Owner

jpsim commented Nov 27, 2019

Thanks for reporting this. Can you see if #235 resolves this for you?

@jpsim
Copy link
Owner

jpsim commented Apr 17, 2020

Thanks for your patience, I've finally come around to finishing a proper fix to this. It's available here: #248

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