# Strange error when calling Dir.exists

**URL:** https://forum.crystal-lang.org/t/strange-error-when-calling-dir-exists/7824
**Category:** Help & Support
**Created:** [March 4, 2025, 7:11pm UTC](https://forum.crystal-lang.org/t/strange-error-when-calling-dir-exists/7824 "2025-03-04T19:11:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Fulgurance](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/fulgurance/32/1463_2.png) [@Fulgurance](https://forum.crystal-lang.org/u/Fulgurance)
#### Post date: [March 4, 2025, 7:11pm UTC](https://forum.crystal-lang.org/t/strange-error-when-calling-dir-exists/7824/1 "2025-03-04T19:11:24Z")

</div>

Hi guys, today when I was doing test after new updates on my software, I got this strange error:

```bash
Would you like to install these softwares ?[yes/no]y

<< [1 / 155] Installing @SystemBase-Main:SystemBase (Pass1) /0.2.0/

&#9632; Preparing installation for SystemBase

===============
Internal error
===============

/snap/crystal/2394/share/crystal/src/crystal/system/unix/file.cr:44:9 in 'info?'
/snap/crystal/2394/share/crystal/src/file.cr:198:5 in 'info?'
/snap/crystal/2394/share/crystal/src/file.cr:197:3 in 'info?'
/snap/crystal/2394/share/crystal/src/dir.cr:255:15 in 'exists?'
.ISM.task.cr:42:1 in 'recordInstallationInformation'
.ISM.task.cr:7462:65 in '__crystal_main'
/snap/crystal/2394/share/crystal/src/crystal/main.cr:118:5 in 'main_user_code'
/snap/crystal/2394/share/crystal/src/crystal/main.cr:104:7 in 'main'
/snap/crystal/2394/share/crystal/src/crystal/system/unix/main.cr:9:3 in 'main'
/lib/x86_64-linux-gnu/libc.so.6 in '??'
/lib/x86_64-linux-gnu/libc.so.6 in '__libc_start_main'
/home/ism/snap/crystal/common/.cache/crystal/crystal-run-.ISM.task.tmp in '_start'
???

ISM raised that error because the ran script did not call properly a system command or the system command itself need to be fix.

```

I inspected the code, and this occur in this function when I try to check **Dir.exists**.  
But why ??? It’s weird no ?

```crystal
def recordInstallationInformation : Tuple(UInt128, UInt128, UInt128, UInt128)
            directoryNumber = UInt128.new(0)
            symlinkNumber = UInt128.new(0)
            fileNumber = UInt128.new(0)
            totalSize = UInt128.new(0)

            filesList = Dir.glob(["#{builtSoftwareDirectoryPathNoChroot}/**/*"], match: :dot_files)

            filesList.each do |entry|

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

                if File.directory?(entry)
                    if !Dir.exists?(finalDestination)
                        directoryNumber += 1
                    end
                else
                    if File.symlink?(entry)
                        symlinkNumber += 1
                    else
                        fileNumber += 1
                        totalSize += File.size(entry)
                    end
                end

            end

            return directoryNumber, symlinkNumber, fileNumber, totalSize

            rescue error
                Ism.printSystemCallErrorNotification(error)
                Ism.exitProgram
        end

```

---

<div class="post-metadata">

### Author: ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)
#### Post date: [March 4, 2025, 7:22pm UTC](https://forum.crystal-lang.org/t/strange-error-when-calling-dir-exists/7824/2 "2025-03-04T19:22:12Z")

</div>

What’s the actual error? Is it actually blank, or is your `printSystemCallErrorNotification` method just not including `error.message`?

---

<div class="post-metadata">

### Author: ![Fulgurance](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/fulgurance/32/1463_2.png) [@Fulgurance](https://forum.crystal-lang.org/u/Fulgurance)
#### Post date: [March 5, 2025, 12:57am UTC](https://forum.crystal-lang.org/t/strange-error-when-calling-dir-exists/7824/3 "2025-03-05T00:57:26Z")

</div>

So as I suspected, the error occured because of permission issue.

But I am happy you raise this point, because now I understand better why the error messages wasn’t so helpful.

This is the function I use to print the error:

```auto
def printSystemCallErrorNotification(error : Exception)
            limit = ISM::Default::CommandLine::InternalErrorTitle.size

            separatorText = String.new

            (0..limit).each do |index|
                separatorText += "="
            end

            fullLog = (error.backtrace? ? error.backtrace.join("\n") : error.message)

            title = "#{ISM::Default::CommandLine::InternalErrorTitle.colorize(:red)}"
            separatorText = "#{separatorText.colorize(:red)}"
            errorText = "\n#{fullLog.colorize(Colorize::ColorRGB.new(255,100,100))}"
            help = "\n#{ISM::Default::CommandLine::SystemCallErrorNotificationHelp.colorize(:red)}"

            puts
            puts separatorText
            puts title
            puts separatorText
            puts errorText
            puts help

            rescue error
                printSystemCallErrorNotification(error)
                exitProgram
        end

```
