ULX

Author Topic: ULib attempt to index 'str' (a nil value): praseKeyValues; removeCommentHeader  (Read 2168 times)

0 Members and 1 Guest are viewing this topic.

Offline Imperial Knight

  • Newbie
  • *
  • Posts: 2
  • Karma: 1
  • gLua/Web Developer
Hey.

So with an addon I'm working on, it appears I get ulib errors on some of ulib's functions, for some reason. I'll provide each line of code for the error.

addons/ulib/lua/ulib/shared/misc.lua:30 (ULib Code)
Code: [Select]
local newpos, endpos = str:find( separator, curpos ) -- find the next separator in the string

addons/ulib/lua/ulib/shared/misc.lua:696 (ULib Code)
Code: [Select]
local lines = ULib.explode( "\r?\n", data )

addons/imbans/lua/autorun/server/ulx_sv_mysql.lua:915 (My Code)
Code: [Select]
local bans, error3 = ULib.parseKeyValues( ULib.removeCommentHeader( ULib.fileRead( ULib.BANS_FILE ), "/" ) )

lua/includes/modules/concommand.lua:54 (Garry's Mod Dedicated Server Code)
Code: [Select]
CommandList[ LowerCommand ]( player, command, arguments, args )

I'm a bit confused as to why it's erroring out there. (I've provided the error below)


My ULib/ULX versions (run "ulx version" in console):
ULib v2.61 (latest as of now)
ULX v3.71 (latest as of now)

Game mode(s) I am having this problem on: Not relevant: any gamemode.

Lua errors shown in console, if any:
Code: [Select]
[ERROR] addons/ulib/lua/ulib/shared/misc.lua:30: attempt to index local 'str' (a
 nil value)
  1. explode - addons/ulib/lua/ulib/shared/misc.lua:30
   2. removeCommentHeader - addons/ulib/lua/ulib/shared/misc.lua:696
    3. unknown - addons/imbans/lua/autorun/server/ulx_sv_mysql.lua:915
     4. unknown - lua/includes/modules/concommand.lua:54

Any help or suggestions with this would be greatly appreciated. If this is an actual issue on ULib's side, I'll create a bug report.

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Code: [Select]
local bans, error3 = ULib.parseKeyValues( ULib.removeCommentHeader( ULib.fileRead( ULib.BANS_FILE ), "/" ) )
Are you checking if ULib.BANS_FILE (data/ulib/bans.txt) exists before trying to read it? ULib.fileRead will return nil if the file does not exist. That would cause the other functions to fail, as they expect a string type argument.

You can refer to the source code for ULib.refreshBans to see how ULib loads bans.
« Last Edit: July 11, 2018, 12:11:51 AM by Timmy »

Offline Imperial Knight

  • Newbie
  • *
  • Posts: 2
  • Karma: 1
  • gLua/Web Developer
Thanks for the reply.

The problem I was having was an addon (custom ban message addon somehow) that was stopping ULX from creating a bans.txt file and instead read the garrysmod/cfg/banned_user.cfg file, which messed with the ULib.BAN_FILE.