#index out of range [0] with length 0: no reason I can see for my code to do this

42 messages · Page 1 of 1 (latest)

rancid pivot
#

okay I have this code I wrote to de-duplicate minecraft mod jars (technic pack stuff) and its having an heart attack for some reasoN

$ go run .
2023/05/06 10:20:59 [RENAME MOD] [ 0 ] Alloy Forgery-2.0.20+1.19.4.jar >> Alloy Forgery-2.0.20+1.19.4.jar
2023/05/06 10:20:59 [RENAME MOD] [ 1 ] Architectury-8.1.80.jar >> Architectury-8.1.80.jar
2023/05/06 10:20:59 [RENAME MOD] [ 2 ] Forge Config API Port-6.0.2.jar >> Forge Config API Port-6.0.2.jar
2023/05/06 10:20:59 [RENAME MOD] [ 3 ] Patchouli-1.19.3-78-FABRIC.jar >> Patchouli-1.19.3-78-FABRIC.jar
2023/05/06 10:20:59 [RENAME MOD] [ 4 ] YUNG's API-1.19.4-Fabric-3.10.1.jar >> YUNG's API-1.19.4-Fabric-3.10.1.jar
2023/05/06 10:20:59 [RENAME MOD] [ 5 ] YUNG's Better Desert Temples-1.19.4-Fabric-2.4.0.jar >> YUNG's Better Desert Temples-1.19.4-Fabric-2.4.0.jar
2023/05/06 10:20:59 [RENAME MOD] [ 6 ] YUNG's Better Dungeons-1.19.4-Fabric-3.4.0.jar >> YUNG's Better Dungeons-1.19.4-Fabric-3.4.0.jar
2023/05/06 10:20:59 [RENAME MOD] [ 7 ] YUNG's Better Mineshafts-1.19.4-Fabric-3.4.0.jar >> YUNG's Better Mineshafts-1.19.4-Fabric-3.4.0.jar
2023/05/06 10:20:59 [RENAME MOD] [ 8 ] YUNG's Better Ocean Monuments-1.19.4-Fabric-2.3.0.jar >> YUNG's Better Ocean Monuments-1.19.4-Fabric-2.3.0.jar
2023/05/06 10:20:59 [RENAME MOD] [ 9 ] YUNG's Better Strongholds-1.19.4-Fabric-3.4.0.jar >> YUNG's Better Strongholds-1.19.4-Fabric-3.4.0.jar
2023/05/06 10:20:59 [RENAME MOD] [ 10 ] YUNG's Better Witch Huts-1.19.4-Fabric-2.3.0.jar >> YUNG's Better Witch Huts-1.19.4-Fabric-2.3.0.jar
2023/05/06 10:20:59 [RENAME MOD] [ 11 ] YUNG's Bridges-1.19.4-Fabric-3.3.0.jar >> YUNG's Bridges-1.19.4-Fabric-3.3.0.jar
2023/05/06 10:20:59 [SKIP] YUNG's Extras-1.19.4-Fabric-3.3.0.jar.dis
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.readMod({0xc0001480c0, 0x23})
        F:/Workspace/jar-debub/main.go:161 +0xd11
main.main()
        F:/Workspace/jar-debub/main.go:67 +0x17c
exit status 2

https://pastebin.com/G9Pb09ea

gray hound
#

@rancid pivot the file you sent is different from the one you ran (since stack trace says line 161 but there is no code on line 161), assuming you removed and a line and everything shifted up.

You try to access forgeMod.Mods[0] when forgeMod.Mods is empty.

#

you can't access the first element of a slice that does not have any element

rancid pivot
#

Ah, I removed the comment on the "clean" filter in the vars

rancid pivot
#
if file.Name == "META-INF/mods.toml" {
    loader = "forge"
    forgeTomlErr := toml.NewDecoder(contents).Decode(&forgeMod)
    if forgeTomlErr != nil {
        log.Println("[DECODE ERROR]", filename)
        log.Fatalln("[DECODE FORGE MOD]", forgeTomlErr)
    }
    break
}
gray hound
#

I could not have the META-INF/mods.toml file while loader == "forge"

rancid pivot
#

just made a tweak,

gray hound
rancid pivot
#

Log if its touching forge code where you say it is

gray hound
#

do you know how to read a stack trace ?

rancid pivot
#

barely

#

oh wait one sec

gray hound
#

One possibility is that the jar you are parsing is not following the format you expect maybe even incorrect.
But if your program crashes instead of returning an error when reading an invalid file imo that a bug.

#

1 sec

rancid pivot
#

bruh

rancid pivot
#

I found the issue I think

#

one of the mods has an forge mods.toml

#

but doesn populate

#

I think

#
modLoader = "javafml"
loaderVersion = "[39,)"
issueTrackerURL = "https://github.com/Skidamek/AutoModpack/issues"
license = "MIT"

[[mods]]
modId = "automodpack"
version = "3.3.0"
displayName = "AutoModpack"
authors = '''
Skidam
Pipelek
Merith
SinisterEmber
'''
description = '''
Just automatic updating and downloading modpacks!
'''
logoFile = "icon.png"

[[dependencies.automodpack]]
modId = "forge"
mandatory = true
versionRange = "[39,)"
ordering = "NONE"
side = "BOTH"

[[dependencies.automodpack]]
modId = "minecraft"
mandatory = true
versionRange = "[1.19,)"
ordering = "NONE"
side = "BOTH"

this somehow is causing it to fail???

#

hmmm... need to handle multi-loader jars then

#

wait it should already do that by following the priority of
fabric
quilt
forge

#

so why is it getting to forge?!

gray hound
#

at this point you need to disprove your theory

#

at the divergence point you need to add a log to see what you are testing vs the real value

rancid pivot
#

watching the debugger now...

gray hound
#

I think here it would be adding a log message here:

+        log(file.Name)
         if file.Name == "META-INF/mods.toml" {
rancid pivot
#

looking at it with debugger

#

okay ran a check before it parses the mod files and

#
if file.Name != "fabric.mod.json" && file.Name != "quilt.mod.json" && file.Name != "META-INF/mods.toml" {
    continue
} else {
    log.Println("[FOUND]", file.Name)
}
#

(I have removed other possible mods

#

ooohhh

#

I see what its doing

#

since mods.toml is in a folder, its getting read before fabric.mod.json and quilt.mod.json

#

this fixes it

if loader == "forge" {
    if len(forgeMod.Mods) != 0 {
        forgeMods = append(forgeMods, forgeMod)
        log.Println("Forge Mod", filename)
        return forgeMod.Mods[0].DisplayName, forgeMod.Mods[0].Version, loader
    }
}