I have a major game breaking bug caused by a script, and I'm not sure how to fix it.

I keep running into "Stack error too deep" every now and then during combat, and my game crashes. It seems to be related to
Shaz's State Add/Remove Commands https://forums.rpgmakerweb.com/index.php?threads/state-add-remove-commands.18593/, and it may be conflicting with another script. Here is a backtracer output:

2019-06-29 01:27:21 -0700 >> EXCEPTION CAUGHT <<
SystemStackError: stack level too deep.
Backtrace:
Shaz - State Commands:95

I'm assuming 95 means Line 95 from the script, so here is the section it's in:
Code:
  #--------------------------------------------------------------------------
  # * State Remove Commands
  #--------------------------------------------------------------------------
  def state_remove_command(state_id)
    $data_states[state_id].note.split(/[\r\n]/).each do |line|
      case line
      when /onremove:\s*(.*)/i
        eval($1)
      end
    end
  end
end
Line 95 is the "eval($1)" part.

The crashing seems to happen randomly when I use attacks that hit multiple times. I am using a bunch of scripts, so I don't know which one could be causing the issue, if it's compatibility related.
I don't know how to fix it, but generally this kind of error happens when a script is calling himself or being called too many times at once.

Check if you have the same function
state_remove_command
somewhere else in your other scripts, to begin with.
The common cause of stack level too deep is when you have duplicated script.
stack level too deep means you're caught in an infinite loop, probably by that instruction triggering a definition of something somewhere, that leads back to itself.
my guess is, that the "on remove" tag is causing the removal of another state, which itself is going through the "on remove" process again.
as stated above this error is not one in the script itself (especially not since Shaz is known to write stable scripts) but something creates a loop inside your code.

that means either the script is installed twice, or there are two different scripts accessing the same override, or the configuration on what to remove is the cause of the loop.

I suggest you check all unnamed slots in the script editor if you can't find a duplicate, because it happened a lot of time that people forgot to name the slot after installing a script, then forgot it was already installed and installed it again.

And I also suggest you follow the link "how to use a script" in my signature to the bughunting section, and use the backtracer to find out where in your scripts that loop is.
as stated above this error is not one in the script itself (especially not since Shaz is known to write stable scripts) but something creates a loop inside your code.

that means either the script is installed twice, or there are two different scripts accessing the same override, or the configuration on what to remove is the cause of the loop.

I suggest you check all unnamed slots in the script editor if you can't find a duplicate, because it happened a lot of time that people forgot to name the slot after installing a script, then forgot it was already installed and installed it again.

And I also suggest you follow the link "how to use a script" in my signature to the bughunting section, and use the backtracer to find out where in your scripts that loop is.
I just checked and there are no duplicate scripts or scripts in the unnamed slots, so it must be one of the other reasons. I'll definitely check out the link in your signature as well.
so it must be one of the other reasons
in that case you'll need the backtracer to find out which scripts are involved.
I got the error to show again after installing the backtracer, and this is in the error log: "Shaz - State Commands: 95 :stack level too deep, SystemStackError". No other information is available. This is what it said in the console as well when the error occurred.
comment out the eval line, let the code run as usual and wait for that error again.
if the eval line is the problem, then it is evaluating something that leads back to itself, so, print it out before that eval happens, and when it happens, you'll see the code it was intended to run.
Code:
p $1.to_s
eval ($1)

if that line has a function call in it that can be remotely tracked back to your code,... voila! that's the culprit.

Original thread: https://forums.rpgmakerweb.com/threads/i-have-a-major-game-breaking-bug-caused-by-a-script-and-im-not-sure-how-to-fix-it.110507/