Can't start mafia with a script on the command line

gleamglade

New member
I often start my char up on a terminal with
Code:
java -jar KoLmafia.jar -Djava.awt.headless=true --CLI gleamglade.kmf
and I don't know what I've done wrong since updating the jar to recent (r26328) and java (which I did recently) but presently it goes

Unexpected error, debug log printed.
Returned: void

I cleared out my script to just run
Code:
 login gleamglade;
exit;
and it results in the same, and I can't find a debug log to try to dig in further. What further steps could I follow to start sorting this out?
I'm on a Debian system.
 

Ryo_Sangnoir

Developer
Staff member
I'd really need the debug log in order to debug further. It should be created in the same directory as KoLmafia.

If no debug log is created in that directory, can you verify that your user can write to the directory / make folders / etc? Try moving the jar somewhere else, e.g. inside your home directory.
 

gleamglade

New member
I'd really need the debug log in order to debug further. It should be created in the same directory as KoLmafia.

If no debug log is created in that directory, can you verify that your user can write to the directory / make folders / etc? Try moving the jar somewhere else, e.g. inside your home directory.
I located the log in /home/me/.kolmafia (rather than the directory ./.kolmafia, which does exist and has often been where it drops things, although I do also have DEBUG_today.txt s in the straight up directory where it's run from) and it reads that it's a NPE:

Code:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
               KoLmafia r26328, Linux, Java 11.0.14
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Please note: do not post this log in the KoLmafia thread of KoL's
 Gameplay-Discussion forum. If you would like the KoLmafia dev team
 to look at it, please write a bug report at kolmafia.us. Include
 specific information about what you were doing when you made this
 and include this log as an attachment.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Timestamp: Wed Apr 06 17:06:16 UTC 2022
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 User:
 Current run: 0
 MRU Script: Unknown
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


Unexpected error, debug log printed.
class java.lang.NullPointerException: null
java.lang.NullPointerException
        at net.sourceforge.kolmafia.textui.Parser.getStringUri(Parser.java:207)
        at net.sourceforge.kolmafia.textui.Parser.makeLocation(Parser.java:5103)
        at net.sourceforge.kolmafia.textui.Parser.makeLocation(Parser.java:5091)
        at net.sourceforge.kolmafia.textui.Parser.makeZeroWidthLocation(Parser.java:5087)
        at net.sourceforge.kolmafia.textui.Parser.error(Parser.java:5392)
        at net.sourceforge.kolmafia.textui.Parser.importFile(Parser.java:369)
        at net.sourceforge.kolmafia.textui.Parser.importFile(Parser.java:346)
        at net.sourceforge.kolmafia.textui.NamespaceInterpreter.refresh(NamespaceInterpreter.java:54)
        at net.sourceforge.kolmafia.textui.NamespaceInterpreter.execute(NamespaceInterpreter.java:38)
        at net.sourceforge.kolmafia.textui.command.CallScriptCommand.call(CallScriptCommand.java:96)
        at net.sourceforge.kolmafia.textui.command.CallScriptCommand.run(CallScriptCommand.java:34)
        at net.sourceforge.kolmafia.KoLmafiaCLI.doExecuteCommand(KoLmafiaCLI.java:453)
        at net.sourceforge.kolmafia.KoLmafiaCLI.executeCommand(KoLmafiaCLI.java:419)
        at net.sourceforge.kolmafia.KoLmafiaCLI.executeLine(KoLmafiaCLI.java:338)
        at net.sourceforge.kolmafia.KoLmafiaCLI.executeLine(KoLmafiaCLI.java:225)
        at net.sourceforge.kolmafia.KoLmafia.main(KoLmafia.java:327)
 

Ryo_Sangnoir

Developer
Staff member
assuming "gleamglade.kmf" is a file which contains the script you want to run, "CallScriptCommand.java:96" is on the path where it can't find the file. Try using an absolute path.

Even so, that doesn't crash for me. What is commandLineNamespace (probably in settings/GLOBAL_prefs.txt) set to?
 

heeheehee

Developer
Staff member
First off, we shouldn't be crashing there.

Parser.getStringUri() evidently expects either this.fileUri != null or this.istream != null. That is being violated.

Apparently AshRuntime#parser violates this, and NamespaceInterpreter (which is generating the error) inherits from that.

I think we should be able to spit out a more informative error if we can bypass this NPE. I expect @Ryo_Sangnoir is on point with that diagnosis, though.
 

heeheehee

Developer
Staff member
r26332 should fix the NPE causing the debug log. I'm nominally going to mark this as fixed, but let us know if you're still running into issues (beyond that namespace thing that Ryo_Sangnoir mentioned), and we'll reopen the bug.
 

gleamglade

New member
OK, now running my KoLmafia.jar (with java -jar -Djava.awt.headless=true /home/me/mafia/KoLmafia.jar --CLI ) results in
Code:
KoLmafia r26328
Build HEAD-49970f9 16.0.1 (AdoptOpenJDK 16.0.1+9) Linux amd64 5.11.0-49-generic

Currently Running on Linux
Local Directory is /home/me/.kolmafia
Using Java 11.0.14

Could not acquire file lock
Initially I added a script, but then tried without with the same results. I also cleared commandLineNamespace setting as instructed by the Using page.
 

heeheehee

Developer
Staff member
Ah, this is a different problem entirely now.

Is there anything funky about
Bash:
ls -l ~/.kolmafia/sessions/active_session.*
?

You typically shouldn't need to manually delete these files, but if Mafia's running as a user that can't edit them (e.g. if they don't have the write bit set), then that's often the simplest option.

This error means that we're encountering issues grabbing a lock on this file, often if it's already held by another file. Do you have another instance of Mafia running? and/or does this persist across a restart?
 

Ryo_Sangnoir

Developer
Staff member
Do you have both "active_session.1" and "active_session.2" files in that directory? If not, it looks like something's stopping Mafia creating files.

Also I see from the quote you have some strange Java versions going on:

> Build HEAD-49970f9 16.0.1 (AdoptOpenJDK 16.0.1+9)

16

> Using Java 11.0.14

11
 

gleamglade

New member
I've given the box a reboot, and gone into ~/.kolmafia/sessions and deleted active_session* (1 & 2 were there) and that seems to have sorted out the starting mafia problem out, however my 'test.kmf' barebones script (and any other I try) now return
Code:
KoLmafia r26333
Build HEAD-74f8864 16.0.1 (AdoptOpenJDK 16.0.1+9) Linux amd64 5.11.0-49-generic

Currently Running on Linux
Local Directory is /home/me/.kolmafia
Using Java 11.0.14

Returned: false
>

My java version is simply what I updated my system to from the debian repositories on it, I haven't done any mucking about with it beyond installing them since mafia moved to the requirement for newer than Java 8, there's a couple of options when I
Code:
 update-alternatives --config java
and I have now switched between them (auto-mode and manual-mode) just to try them out and see if I get any different response.
 

Ryo_Sangnoir

Developer
Staff member
My guess is that the 16 is the version that was used to build the jar. Just so it's off the list of possibilities, could you try using Java 17?
 

MCroft

Developer
Staff member
Can you break out the commands? i.e. start the CLI and then run the script?

You might also look at the permissions of files/directories under /home/me/.

I'd also look at umask, to see if there is any weirdness in the permissions of files that are created.

Then I would try as a different user, perhaps a new one created just for this test.

The goal of these tests is to isolate which part of the system is not acting as expected.
 

gleamglade

New member
Can you break out the commands? i.e. start the CLI and then run the script?

You might also look at the permissions of files/directories under /home/me/.

I'd also look at umask, to see if there is any weirdness in the permissions of files that are created.

Then I would try as a different user, perhaps a new one created just for this test.

The goal of these tests is to isolate which part of the system is not acting as expected.
I think I have it sorted.
As advised I updated to Java 17. This initial step didn't seem to make any difference so I kept at it.
I linked all the default directories in ~/.kolmafia to my corresponding ~/mafia/ directories and was still getting 'Cannot invoke' errors,
so I copied my scripts into /mafia/scripts/mine from /mafia and, having stopped specifying which directory to run them from, now seem to be getting the correct results.
 

fronobulax

Developer
Staff member
I think I have it sorted.
As advised I updated to Java 17. This initial step didn't seem to make any difference so I kept at it.
I linked all the default directories in ~/.kolmafia to my corresponding ~/mafia/ directories and was still getting 'Cannot invoke' errors,
so I copied my scripts into /mafia/scripts/mine from /mafia and, having stopped specifying which directory to run them from, now seem to be getting the correct results.

By design mafia is not supposed to execute scripts from arbitrary locations on the user's file system. If the jar file is in ~/.kolmafia then one allowed place for scripts is ~/.kolmafia /scripts and by extenstion ~/.kolmafia /scripts/mine Usually there is a different response to asking mafia to run a script from another location so the problem didn't jump out immediately. Running headless and running a startup script from the command line (as opposed to a login script executed during start up) are somewhat unusual. Glad things now run.
 
Top