Problem when my function return a Tuple

Hi everyone, I am facing recently a problem after I updated my code on my project.
When I call this function, at runtime crystal complain about that function can return a Tuple(UInt128, UInt128, UInt128, UInt128) or NIL.

How that is possible ?

def install : Tuple(UInt128, UInt128, UInt128, UInt128)
            Ism.notifyOfInstall(@information)

            filesList = Dir.glob(["#{builtSoftwareDirectoryPath(false)}/**/*"], match: :dot_files)
            installedFiles = Array(String).new

            directoryNumber = UInt128.new(0)
            symlinkNumber = UInt128.new(0)
            fileNumber = UInt128.new(0)
            totalSize = UInt128.new(0)

            filesList.each do |entry|

                finalDestination = "/#{entry.sub(builtSoftwareDirectoryPath(false),"")}"

                if File.directory?(entry)
                    if !Dir.exists?(finalDestination)
                        directoryNumber += 1

                        makeDirectory(finalDestination)
                        installedFiles << "/#{finalDestination.sub(Ism.settings.rootPath,"")}".squeeze("/")
                    end
                else
                    if File.symlink?(entry)
                        symlinkNumber += 1
                    else
                        fileNumber += 1
                        totalSize += File.size(entry)
                    end

                    moveFile(entry,finalDestination)
                    installedFiles << "/#{finalDestination.sub(Ism.settings.rootPath,"")}".squeeze("/")
                end

            end

            Ism.addInstalledSoftware(@information, installedFiles)
            return directoryNumber, symlinkNumber, fileNumber, totalSize
        end

Can you share the actual error? I’m unable to reproduce this by just commenting out stuff that I don’t have defined, so are you sure you’re not re-defining this method or something somewhere else that is conflicting with it?

Yes my bad, sorry I wrote that issue quickly before I left home.

So that is the error I have:

Error: undefined method '[]' for Nil (compile-time type is (Tuple(UInt128, UInt128, UInt128, UInt128) | Nil))

And how are you using this method? Is the code like:

install_counts = install

pp install_counts[0]

or?

This is how it’s called:

begin
                            target.download
                            target.check
                            target.extract
                            target.patch
                            target.prepare
                            target.configure
                            target.build
                            target.prepareInstallation

                            directoryNumber, symlinkNumber, fileNumber, totalSize = target.install

                            Ism.recordInstallationDetails(directoryNumber, symlinkNumber, fileNumber, totalSize)

                            target.recordNeededKernelFeatures
                            target.clean
                        rescue
                            if File.exists?(target.information.installedFilePath)
                                Ism.removeInstalledSoftware(target.information)
                            end

                            Ism.exitProgram
                        end

Sorry I find the reason I think.

It’s because there is a case when my script will call another class it inherit from that class it define the install function, but was returning nothing. I forgot to update it

1 Like

Called it :stuck_out_tongue:

1 Like

Ah ah sorry, I just realize I missed that advice from you :rofl:

Well putted, I deserve it :face_with_hand_over_mouth:

Thanks for you help again anyway !

I will be in holidays soon. I plan to do an official video in english about my project, I will have time. Because the project actually start to become very functional now, and I need to show it more now (I need beta tester as well xD)