Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Bad Error Message #547

Closed
goganchic opened this issue May 29, 2018 · 5 comments
Closed

Bad Error Message #547

goganchic opened this issue May 29, 2018 · 5 comments

Comments

@goganchic
Copy link
Contributor

I've opened MSON specification and found such example https://github.com/apiaryio/mson/blob/master/MSON%20Specification.md#232-value-member-types so I've created such piece of code:

# Tesla

## Users [POST /users]

+ Response 200 (application/json)
    + Attributes
        + (array)
            + foo
            + bar

I use drafter from master and it reports me such an error:

drafter: ../src/refract/Element.h:76: const DataType& refract::Element< >::get() const [with DataType = refract::dsd::String]: Assertion `hasValue_' failed.

Is it bug or I've done something wrong?

P.s. such example works fine:

# Tesla

## Users [POST /users]

+ Response 200 (application/json)
    + Attributes (array)
        + foo
        + bar
@pksunkara
Copy link
Contributor

You have done something wrong. Attributes is an object, but you gave it a value member with (array). The error should have a better message though.

@goganchic
Copy link
Contributor Author

ok, thanks!

@pksunkara pksunkara reopened this May 29, 2018
@pksunkara
Copy link
Contributor

No, we need to keep this open to have a better error message.

@goganchic
Copy link
Contributor Author

ok

@pksunkara pksunkara changed the title Assertion `hasValue_' failed Bad Error Message May 29, 2018
@kylef
Copy link
Member

kylef commented Jun 5, 2018

The following patch will restore Drafter 3.2.7 behaviour. Although I do not think this is correct and we should likely catch the problem earlier. I think GetKeyAsString() should require an actual key to be there as it does in master. @tjanc what do you think?

diff --git a/src/refract/VisitorUtils.cc b/src/refract/VisitorUtils.cc
index 8192a8c9..6a1d2b08 100644
--- a/src/refract/VisitorUtils.cc
+++ b/src/refract/VisitorUtils.cc
@@ -27,7 +27,9 @@ std::string refract::GetKeyAsString(const MemberElement& e)
     auto element = e.get().key();

     if (auto str = TypeQueryVisitor::as<const StringElement>(element)) {
-        return str->get();
+        if (!str->empty()) {
+            return str->get();
+        }
     }

     if (auto ext = TypeQueryVisitor::as<const ExtendElement>(element)) {

klokane pushed a commit that referenced this issue Jun 7, 2018
klokane pushed a commit that referenced this issue Jun 7, 2018
pksunkara added a commit that referenced this issue Jun 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants