# JsonIn() Error on Character Creation

**URL:** https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568
**Category:** The Garage
**Created:** [March 23, 2014, 8:56pm UTC](https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568 "2014-03-23T20:56:30Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Mattaclysm](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@Mattaclysm](https://discourse.cataclysmdda.org/u/Mattaclysm)
#### Post date: [March 23, 2014, 8:56pm UTC](https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568/1 "2014-03-23T20:56:30Z")

</div>

I dusted off my Cata GitHub fork to do some debugging (Code:Blocks).

git fetch upstream  
git checkout master  
git reset --hard upstream/master  
git push origin master --force

I haven’t added or modified any code, but I’m still getting an error on character creation in Curses version of the latest experimental (4b8532623f):

 ![](http://i.imgur.com/13JCMkb.png)

Can anyone deduce from the screenshot which .json file is having problems?

Troubleshooting I’ve done:

[ul][li]Tried both Release/Debug profiles[/li]  
[li]Re-created world[/li]  
[li]Tried multiple ways to generate character (Random, Preset, etc.)[/li][/ul]

---

<div class="post-metadata">

### Author: ![i2amroy](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/i2amroy/32/909_2.png) [@i2amroy](https://discourse.cataclysmdda.org/u/i2amroy)
#### Post date: [March 23, 2014, 9:14pm UTC](https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568/2 "2014-03-23T21:14:23Z")

</div>

Does the game produce a debug message? A lot of the JSON error stuff is listed in those messages in-game.

---

<div class="post-metadata">

### Author: ![Mattaclysm](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@Mattaclysm](https://discourse.cataclysmdda.org/u/Mattaclysm)
#### Post date: [March 23, 2014, 9:28pm UTC](https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568/3 "2014-03-23T21:28:08Z")

</div>

I re-tried running the game in Release to see if I could replicate the problem, but no in-game DEBUG message appears and my character seems to load without incident. The error only happens when I debug. I’m using this debugger:

GNU gdb (GDB) 7.4

I haven’t changed anything from the default in Code::Blocks…I also have VS 2010, but I noticed it threw about 8 errors when I loaded up the solution from the msvc100 folder and tried to build.

---

<div class="post-metadata">

### Author: ![BevapDin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/bevapdin/32/228_2.png) [@BevapDin](https://discourse.cataclysmdda.org/u/BevapDin)
#### Post date: [March 23, 2014, 9:48pm UTC](https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568/4 "2014-03-23T21:48:46Z")

</div>

In the bottom left of the window it says buffer: CSC\_WEAPON\_PIERCING, that’s part of the recipes.json file. Also the stacktrace has load\_recipe in it, so it actually fails to load a recipe.

---

<div class="post-metadata">

### Author: ![Mattaclysm](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@Mattaclysm](https://discourse.cataclysmdda.org/u/Mattaclysm)
#### Post date: [March 23, 2014, 10:08pm UTC](https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568/5 "2014-03-23T22:08:43Z")

</div>

Hmm, that’s odd. I did a Compare in Notepad++ of my recipes.json and the one from the repo and the files match. Does that mean there’s a bug with recipes.json, or is this a phantom debugger problem?

---

<div class="post-metadata">

### Author: ![BevapDin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/bevapdin/32/228_2.png) [@BevapDin](https://discourse.cataclysmdda.org/u/BevapDin)
#### Post date: [March 23, 2014, 10:46pm UTC](https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568/6 "2014-03-23T22:46:47Z")

</div>

You can compare your code to the upstream version:

```auto

```

Also that error should lead to a debug message, what does it say?

---

<div class="post-metadata">

### Author: ![Mattaclysm](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@Mattaclysm](https://discourse.cataclysmdda.org/u/Mattaclysm)
#### Post date: [March 24, 2014, 12:39am UTC](https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568/7 "2014-03-24T00:39:59Z")

</div>

The git diff command returned with nothing, so recipes.json must be identical to upstream. As for the debug message, all I see in the actual executable is the “Please wait while the world data loads” overlay on the home screen. Trying to Continue in Code::Blocks just keeps throwing the error.

I saved my previous custom .cbp file that I used to use, but it’s radically different. One thing I’m noticing is that there’s no mention of “makefile” anywhere in the current CataclysmWin.cbp…is that part of the problem?

[Previous .cbp file](http://pastebin.com/CrAyr88F)

EDIT: I re-made the project from a .zip directly from the repo, just to be sure it wasn’t some problem with my fork. Same error.

---

<div class="post-metadata">

### Author: ![Mattaclysm](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@Mattaclysm](https://discourse.cataclysmdda.org/u/Mattaclysm)
#### Post date: [March 24, 2014, 2:14am UTC](https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568/8 "2014-03-24T02:14:55Z")

</div>

I checked the load\_recipe() function in the call stack. The recipe it’s getting stuck on is for javelin, every time. I looked at the json, but the formatting looks okay. Can anyone spot something there that I don’t see? It’s around line 1156.

I foolishly forgot to expand the “message” local variable in my screenshot: It reads:

```auto

```

---

<div class="post-metadata">

### Author: ![Soyweiser](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/soyweiser/32/37_2.png) [@Soyweiser](https://discourse.cataclysmdda.org/u/Soyweiser)
#### Post date: [March 24, 2014, 1:14pm UTC](https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568/9 "2014-03-24T13:14:15Z")

</div>

Perhaps related to the new [["cook… thing? Try removing that line.

---

<div class="post-metadata">

### Author: ![Sean\_Mirrsen](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@Sean\_Mirrsen](https://discourse.cataclysmdda.org/u/Sean_Mirrsen)
#### Post date: [March 24, 2014, 2:03pm UTC](https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568/10 "2014-03-24T14:03:35Z")

</div>

[quote=“Soyweiser, post:9, topic:5568”]Perhaps related to the new [["cook… thing? Try removing that line.[/quote]The error is definitely pointing at the array-of-arrays skill list, or rather the trying to load it (line 90 in crafting.cpp), but - that section is clearly put into a try-catch clause and it really shouldn’t cause anything - unless your debugger is set to throw errors on any and all exceptions.

> if (!jsarr.empty()) { // could be a single requirement, or multiple try { // try to parse as single requirement requires\_skills[jsarr.get\_string(0)] = jsarr.get\_int(1); \<--line 90 } catch (std::string e) { // get\_string or get\_int failed, so assume array of arrays while (jsarr.has\_more()) { JsonArray ja = jsarr.next\_array(); requires\_skills[ja.get\_string(0)] = ja.get\_int(1); } } }

---

<div class="post-metadata">

### Author: ![Mattaclysm](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@Mattaclysm](https://discourse.cataclysmdda.org/u/Mattaclysm)
#### Post date: [March 24, 2014, 11:14pm UTC](https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568/11 "2014-03-24T23:14:50Z")

</div>

Sean, that makes complete sense. How can I make the GDB only report uncaught exceptions?

---

<div class="post-metadata">

### Author: ![Sean\_Mirrsen](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@Sean\_Mirrsen](https://discourse.cataclysmdda.org/u/Sean_Mirrsen)
#### Post date: [March 25, 2014, 3:40am UTC](https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568/12 "2014-03-25T03:40:09Z")

</div>

[quote=“Mattaclysm, post:11, topic:5568”]Sean, that makes complete sense. How can I make the GDB only report uncaught exceptions?[/quote]I can’t find how to do that (heck, I can’t find how to configure the darn thing at all), but having tried out the debug function, it seems you can just power through using Continue, because there’s only a few items that throw these exceptions.

---

<div class="post-metadata">

### Author: ![Mattaclysm](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@Mattaclysm](https://discourse.cataclysmdda.org/u/Mattaclysm)
#### Post date: [March 26, 2014, 1:16am UTC](https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568/13 "2014-03-26T01:16:03Z")

</div>

You’re right, again, Sean. The game continues after about 9 items. I really dislike the try/catch code for the JSON parsing, but I don’t know enough about JSON or C++ to propose a better option. Thanks for all the suggestions, everyone. You’ve helped me get debugging up and running!

Perhaps something like istream::peek exists for JSON parsing to check if there’s more than one skill required without triggering an exception?

EDIT: I took another look through the code, and it looks like we already have JsonIn::peek(). I’m hoping a better solution can be found to remedy the try/catch problem in crafting.cpp.

---

<div class="post-metadata">

### Author: ![Sean\_Mirrsen](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@Sean\_Mirrsen](https://discourse.cataclysmdda.org/u/Sean_Mirrsen)
#### Post date: [March 26, 2014, 7:16am UTC](https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568/14 "2014-03-26T07:16:30Z")

</div>

[quote=“Mattaclysm, post:13, topic:5568”]You’re right, again, Sean. The game continues after about 9 items. I really dislike the try/catch code for the JSON parsing, but I don’t know enough about JSON or C++ to propose a better option. Thanks for all the suggestions, everyone. You’ve helped me get debugging up and running!

Perhaps something like istream::peek exists for JSON parsing to check if there’s more than one skill required without triggering an exception?

EDIT: I took another look through the code, and it looks like we already have JsonIn::peek(). I’m hoping a better solution can be found to remedy the try/catch problem in crafting.cpp.[/quote]There’s a “has\_array()” you can check for, substituting the try-catch for

` if (!jsarr.empty()) {
        // could be a single requirement, or multiple
        if(!jsarr.has_array(0)){ // test if not array
            requires_skills[jsarr.get_string(0)] = jsarr.get_int(1);
        } else {
            //it's not NOT an array, so jsarr is an array of arrays
            while (jsarr.has_more()) {
                JsonArray ja = jsarr.next_array();
                requires_skills[ja.get_string(0)] = ja.get_int(1);
            }
        }
    }`

---

<div class="post-metadata">

### Author: ![Mattaclysm](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@Mattaclysm](https://discourse.cataclysmdda.org/u/Mattaclysm)
#### Post date: [March 26, 2014, 10:52pm UTC](https://discourse.cataclysmdda.org/t/jsonin-error-on-character-creation/5568/15 "2014-03-26T22:52:05Z")

</div>

That works beautifully! No more hitting “Continue” through a bunch of exceptions 🙂

I see you’ve got an account on GitHub. Want to make a quick PR for this fix? I tested a few recipes in game using your code and everything seems to work normally.
