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

parse error - unexpected <uninitialized> with 2.0.5 #325

Closed
alvarolb opened this issue Oct 9, 2016 · 5 comments
Closed

parse error - unexpected <uninitialized> with 2.0.5 #325

alvarolb opened this issue Oct 9, 2016 · 5 comments
Labels
solution: invalid the issue is not related to the library

Comments

@alvarolb
Copy link

alvarolb commented Oct 9, 2016

Hi,

I have been using this library for a long time now. Today, after updating to 2.05, my program started to crash while parsing a simple JSON file. Here is the sample json:

{
    "http_server" : {
      "address" : "0.0.0.0",
      "port" : "8080",
      "hosts" : [
        {
            "host": "*",
            "type":"rest"
        }
      ]
    },

    "thing_server" : {
      "address" : "0.0.0.0",
      "port" : "25200"
    },

    "database" : {
        "type" : "mongodb",
        "mongodb" : {
            "host" : "localhost",
            "password" : ""
        }
    },

    "buckets" : {
        "storage" : {
            "type" : "mongodb",
            "mongodb" : {
                "host" : "localhost",
                "password" : "",
                "database" : "thinger_data",
                "table" : "buckets_data"
            }
        },
        "export" : {
            "type" : "filesystem",
            "filesystem" : {
                "export_path": "/Users/alvarolb/Desktop/buckets_exports"
            }
        }
    },

    "log" : {
        "enabled" : true,
        "level" : "debug",
        "output" : {
            "file" : {
                "enabled" : false,
                "flush" : false
            },
            "clog" : {
                "enabled" : true
            }
        }
    },

    "accounts" : {
      "invalid_usernames" : ["admin", "moderator", "administrator", "mod", "sys", "system", "community", "info", "you", "name", "me", "username", "user", "nickname", "thinger", "root"],
      "invalid_email_domains" : ["mailinator.com"],
      "required_email_domains" : [],
      "require_email_verification": true,
      "min_password_length" : 6
    }
}

The code is something like:

std::ifstream file("config.json");
std::string json_config_str((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
file.close();
nlohmann::json config = nlohmann::json::parse(json_config_str);

The error given is:
libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: parse error - unexpected <uninitialized>

I have tested the same code with 2.04, and 2.03, and I am still getting the same error. Meanwhile, I have switch back to 2.02 that was working fine with this file. I have tested that the JSON is valid also.

Thanks for your support and your awesome work!

@nlohmann
Copy link
Owner

nlohmann commented Oct 9, 2016

I cannot reproduce the error. I'm using the current code from the develop branch as well as the 2.0.5 release:

#include <fstream>
#include <json.hpp>

using json = nlohmann::json;

int main()
{
    std::ifstream f("issue325.json");
    json j = json::parse(f);
    std::cout << j << std::endl;
}

The output is

{"accounts":{"invalid_email_domains":["mailinator.com"],"invalid_usernames":["admin","moderator","administrator","mod","sys","system","community","info","you","name","me","username","user","nickname","thinger","root"],"min_password_length":6,"require_email_verification":true,"required_email_domains":[]},"buckets":{"export":{"filesystem":{"export_path":"/Users/alvarolb/Desktop/buckets_exports"},"type":"filesystem"},"storage":{"mongodb":{"database":"thinger_data","host":"localhost","password":"","table":"buckets_data"},"type":"mongodb"}},"database":{"mongodb":{"host":"localhost","password":""},"type":"mongodb"},"http_server":{"address":"0.0.0.0","hosts":[{"host":"*","type":"rest"}],"port":"8080"},"log":{"enabled":true,"level":"debug","output":{"clog":{"enabled":true},"file":{"enabled":false,"flush":false}}},"thing_server":{"address":"0.0.0.0","port":"25200"}}

@nlohmann nlohmann added the state: please discuss please discuss the issue or vote for your favorite option label Oct 9, 2016
@alvarolb
Copy link
Author

Not sure if it may be related with the compiler version, but I am using clang 3.8.1 on Mac.
I have tested in two different environments (using clang and mac) and I am getting the same error on both.
What can I do to help in the debugging process?

@nlohmann
Copy link
Owner

I now also tried your code:

#include <fstream>
#include <json.hpp>

using json = nlohmann::json;

int main()
{
    std::ifstream file("config.json");
    std::string json_config_str((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
    file.close();
    nlohmann::json config = nlohmann::json::parse(json_config_str);
    std::cout << config << std::endl;
}

It also worked without problems.

To rule out compilers: I am using macOS Sierra with Apple LLVM version 8.0.0 (clang-800.0.38). I shall add a test case and let it run through the compilers at Travis and AppVeyor - maybe the bug is triggered there.

To help debugging, you may try on of the following:

  • Step through the parser to locate the position where the exception is raised.
  • Make sure the string json_config_str is filled properly.
  • Try the parser call from my first snippet.
  • Reduce the input file to a smaller version which still triggers the exception.

@nlohmann nlohmann changed the title parse error - unexpected <uninitialized> with 2.05 parse error - unexpected <uninitialized> with 2.0.5 Oct 10, 2016
@alvarolb
Copy link
Author

Sorry for your time @nlohmann I have isolated the project to the basic example, and it just worked fine. Then I realized that I was mixing two different versions of the library in the project (in different folders). One with the 2.02 and, other with 2.05. When using 2.02 it worked since both versions were the same, however, while using 2.05 along with 2.02, it compiled but crashed at runtime.

Thanks for your support and your awesome library.

@nlohmann nlohmann added solution: invalid the issue is not related to the library and removed state: please discuss please discuss the issue or vote for your favorite option labels Oct 10, 2016
@nlohmann
Copy link
Owner

No worries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

2 participants