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

No Error Explanation in User-Defined Pack & Unpack #21

Open
nordlow opened this issue Nov 22, 2013 · 4 comments
Open

No Error Explanation in User-Defined Pack & Unpack #21

nordlow opened this issue Nov 22, 2013 · 4 comments

Comments

@nordlow
Copy link
Contributor

nordlow commented Nov 22, 2013

Classes with errorneous user-defined msgpacking, such as


/** Directory Kind.
 */
class DirKind {
    this(string fn,
         string kn) {
        this.fileName = fn;
        this.kindName = kn;
    }

    version (msgpack) {
        this(Unpacker)(ref Unpacker unpacker) {
            fromMsgpack(msgpack.Unpacker(unpacker));
        }
        void toMsgpack(Packer)(ref Packer packer) const {
            packer.beginArray(this.tupleof.length);
            packer.pack(this.tupleof);
            errror_here;
        }
        void fromMsgpack(Unpacker)(auto ref Unpacker unpacker) {
            unpacker.beginArray();
            unpacker.unpack(this.tupleof);
        }
    }

    string fileName;
    string kindName;
}
version (msgpack) unittest {
    auto k = tuple("", "");
    auto data = pack(k);
    Tuple!(string, string) k_; data.unpack(k_);
    assert(k == k_);
}

makes the compiler error without any usable explanations:

/home/per/Work/justd/msgpack.d(807): Error: static assert  "Failed to invoke 'toMsgpack' on type 'Dir'"
/home/per/Work/justd/msgpack.d(4349):        instantiated from here: pack!(Dir)
/home/per/Work/justd/fs.d(850):        instantiated from here: pack!(false, Dir)
/home/per/Work/justd/fs.d(2056):        instantiated from here: saveDirTree!(Terminal)
/home/per/Work/justd/fs.d(2076):        instantiated from here: fs!(Terminal)

Compilation exited abnormally with code 1 at Fri Nov 22 19:43:51
@repeatedly
Copy link
Member

"Failed to invoke 'toMsgpack' on type 'Dir'" shows Dir's toMsgpack can't pass a compilation check.

Hmm, do you have a suggestion?

@nordlow
Copy link
Contributor Author

nordlow commented Jan 18, 2014

The problem is your use of __traits(compiles....).

You overuse them in the error handling in msgpack.d.

For example

        static if (__traits(compiles, { T t; t.toMsgpack(this, withFieldName_); })) {
            object.toMsgpack(this, withFieldName_);
        } else static if (__traits(compiles, { T t; t.toMsgpack(this); })) { // backward compatible
            object.toMsgpack(this);
        } else {
            object.toMsgpack(this);
            static assert(0, "Failed to invoke 'toMsgpack' on type '" ~ T.stringof ~ "'");
        }

should be replaced with

        static if (__traits(compiles, { T t; t.toMsgpack(this, withFieldName_); })) {
            object.toMsgpack(this, withFieldName_);
        } else {
            object.toMsgpack(this);
        }

Do you want me to fix and provide and pull request or do you want to do it yourself?

@ghost
Copy link

ghost commented Feb 3, 2014

I did suggest this sort of thing before: #2 (comment)

@nordlow
Copy link
Contributor Author

nordlow commented Feb 28, 2014

I don't understand...how can something be more important than having the possibility to know what error I have done in my pack or unpack function?

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

No branches or pull requests

2 participants