Error in core while using get_value()

Discussion in 'CommandHelper' started by Nolz, Nov 8, 2018.

  1. Nolz

    Nolz New Member


    We just ran into a core error, somehow. It seems that whenever our script tries to retrieve a specific key from persistence, it causes CH to throw this exception. The line its failing on is;
    Code (Text):
    @activeworlds = get_value("shard.server."[email protected]".activeworlds")
    Other get_value() calls work just fine; it seems to be only this one that is giving us problems.

    From what we can tell, the issue might be caused by a stray newline at the end of the @server variable (note how the function is split across line 4 & 5 on the pastebin). There is no reason for that to be there though, as it doesn't appear if we throw the variable in chat using msg().

    We're using CommandHelper build #3426, which is the latest 1.12.2-compatible build. We're unable to update to any of the 1.13 builds until we can get our lobby server finished, which requires us to get this error fixed. The server software we're using is PaperSpigot build #1587.

    Many thanks in advance!
  2. PseudoKnight

    PseudoKnight Well-Known Member Developer

    should have a better error message, but the only way that I can see this happening is if it can't find a data source connection for that key in your persistence.ini file. It might be related to that new line that may or may not be in @server, but it doesn't seem like that would be from CH. It may be helpful to see your persistence.ini file and whatever assigned/modified @server.
    Last edited: Nov 9, 2018
  3. Nolz

    Nolz New Member

    We only have one connection set up in persistence.ini, which works fine for all other persistence functions. I don't think that's the issue.

    @server gets assigned as follows;

    Each of our servers run on AWS instances. To figure out what their ID is, they run this in;
    Code (Text):

    shell('chmod 744 ""',array(workingDir: '/opt/Shard/Scripts'))
    @id = shell('./' @shardid,array(workingDir:'/opt/Shard/Scripts'))
    @id = reg_replace('"','',@id)
    console("Server ID is "[email protected]" Newline test")
    Note; the "Newline test" part of the console() line appears on the same line as the rest of that message, indicating that there's no newline added there. Server IDs are something like "vanilla_11304888111276339"

    Then, using that ID, the server figures out what kind of server its supposed to be (either a lobby server, or a regular server). If the server is a regular server (in our tests it was), the ID is stored in an array, which is then stored in a "serverpool" key in persistence.

    Code (Text):

    @split = split("_", @id)
    export("serverpool", @split[0])
    console("Serverpool is "[email protected][0])
    @serverpool = get_value("shard.serverpool."[email protected][0])
       @serverpool = array()
    if(to_lower(@split[1]) == "devlobby" || to_lower(@split[1]) == "lobby"){
       @servermode = "LOBBY"
    } else {
       @servermode = "SHARD"
       @serverpool[] = @id
    console("Servermode is "[email protected])
    export("servermode", @servermode)
    store_value("shard.serverpool."[email protected][0], @serverpool)
    Finally, in another script, this serverpool key is retrieved, and the script loops through each ID contained within the array.
    Code (Text):

    @serverpool = get_value("shard.serverpool."[email protected])
           @slotcandidates = array(dummy: 1000000000)
           foreach(@server in @serverpool){
             @activeworlds = get_value("shard.server."[email protected]".activeworlds")
    The "activeworlds" key is an array containing a list of worlds that the server has currently loaded. This key doesn't necessarily exist all the time (which I just realized I forgot to account for), but that shouldn't matter, since get_value() is supposed to return "null" when the key doesn't exist.
  4. PseudoKnight

    PseudoKnight Well-Known Member Developer

    Ya, probably some kind of character being inserted at the end of the output from shell(). If you wrap @id in length() you'll probably see it's one too many characters. Wrapping @id in trim() will probably fix this for you.

    Some things I might need to discuss with LadyCailin to figure out what's normal behavior.
  5. Nolz

    Nolz New Member

    Unfortunately, that's not the problem. Wrapping @id in length() shows that its 25 characters long, which is correct. There's no hidden characters at the beginning/end of it.
  6. PseudoKnight

    PseudoKnight Well-Known Member Developer

    Then it would have to be right before ".activeworlds".
  7. Nolz

    Nolz New Member

    There's indeed a newline character at the variable at the end of the @server variable. But that character isn't there when we store the server's ID in the "shard.serverpool" key, and that key is never modified anywhere else. There's no reason for that newline to magically appear like that.
  8. PseudoKnight

    PseudoKnight Well-Known Member Developer

    So you're saying the value you put into an array and store with store_value("shard.serverpool."[email protected][0], @serverpool) changes by the time it's retrieved with @serverpool = get_value("shard.serverpool."[email protected]). If you can verify that, it helps narrow it down. Also, make sure you're actually comparing the same value and not some leftover value in that stored array.

    For good measure I just scanned over this part of the code and didn't find anything suspect. What persistence file type are you using? Default sqlite?
  9. Nolz

    Nolz New Member

    That is correct. The string is 25 characters when it gets added to the array, and then becomes 26 characters when the array is retrieved.

    We're using MySQL as database. Though I'm not the one who set it up, so I'm not sure how its configured exactly.

    EDIT: Actually now that I think of it, we had a different issue with newline symbols earlier and an old value might still be stuck in that array. I'll have to check.
  10. Nolz

    Nolz New Member

    Yep, that was the problem. There was a single leftover value in the array, which still had a newline character at the end. Now that that's gone, its working perfectly.

    Should've probably noticed that earlier. Oh well.

    Many thanks, PseudoKnight!
  11. PseudoKnight

    PseudoKnight Well-Known Member Developer

    We talked about the core error. In a future build of CH 3.3.3 it'll throw a more helpful FormatException when a new line sneaks into the string given to persistence functions. It was six year old code, so it needed a little revisit.

    I'm happy you tracked it down. If you ever need more live support, we're also on irc and discord.
  12. Oboist

    Oboist Member

    Can you post a discord link, please? Cannot find it neither on MethodScript website, nor in the old wiki.
  13. PseudoKnight

    PseudoKnight Well-Known Member Developer