1. SirAlaran
  2. dscanner

Commits

SirAlaran  committed 49c43c8

Better error handling in the case of missing files

  • Participants
  • Parent commits d7afc3b
  • Branches default

Comments (0)

Files changed (1)

File scanner.d

View file
  */
 Module loadModule(string filePath)
 {
+	if (filePath is null)
+		return null;
 	Module mod = new Module();
 	mod.filePaths ~= filePath;
 	string input = readText(filePath);
 }
 }
 
-void main(string[] args)
+int main(string[] args)
 {
 	/// Directories to search for imports
 	string[] dirs;
 	if (args.length <= 1)
 	{
 		stderr.writeln("No source files specified");
-		return;
+		return 1;
 	}
 
 	getopt(args, "I", &dirs, "help|h", &help, "markup|m", &markup,
 	if (help)
 	{
 		printHelp(args[0]);
-		return;
+		return 1;
 	}
 
 	if (markup)
 	{
 		printSourceFile(readText(args[1]));
-		return;
+		return 0;
 	}
 
 	if (isAbsolute(args[1]))
 	dirs.insertInPlace(dirs.length, loadConfig());
 
 	Module mod = loadModule(findAbsPath(dirs, args[1]));
+	if (mod is null)
+	{
+		stderr.writeln("Could not find ", args[1]);
+		return 1;
+	}
 	ModuleMerger merger = new ModuleMerger(mod);
 	if (!ignoreImports)
 	{
 				if (importPath is null)
 					continue;
 				Module importedModule = loadModule(importPath);
-				merger.merge(importedModule, importPath);
+				if (importedModule !is null)
+					merger.merge(importedModule, importPath);
 			}
 		}
 	}
 	else
 		mod.writeJSON(stdout);
 	writeln();
+	return 0;
 }