Neat-Lang / neat

The Neat Language compiler. Early beta?
BSD 3-Clause "New" or "Revised" License
111 stars 9 forks source link

Crash when using directory instead of file name for compilation #39

Closed wilsonk closed 10 months ago

wilsonk commented 10 months ago

I get a segmentation fault when accidentally trying to compile a directory like this: neat halma/. Here is a bit of code, that can be placed at line 1077 or so of main.nt, to avoid this (too small for a PR, IMHO):

    for (arg in args) {
        if (arg.startsWith("-"))
            continue;
        if (basename(arg) == "") {
            print("You need to specify a file and not a directory.");
            return;
        }
    }

I am sure that code could be more robust ;)

Perhaps it would be better to check the directory to see if it has a package.json file, and if it does then cwd into that dir and do a neat build instead of failing with that message? Only fail with the message if there is no package.json file in the dir? Not sure which design you would like to follow.

FeepingCreature commented 10 months ago

I just added a isRegularFile check.