Skip to content

Commit

Permalink
Add proper warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed Apr 26, 2022
1 parent ff888cb commit f5cb4d8
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ void trace(string func = __FUNCTION__, A...)(string fmt, A args)
writefln(fmt, args);
}

void printWarning(string func = __FUNCTION__, A...)(string fmt, A args)
{
stderr.write("warning: ");
debug stderr.write("[", func, "] ");
stderr.writefln(fmt, args);
}
int printError(string func = __FUNCTION__, A...)(int code, string fmt, A args)
{
stderr.writef("error: (code %d) ", code);
Expand Down Expand Up @@ -208,7 +214,8 @@ unittest
assert(s == 1024 + 102); // 102.4
}

bool compareHash(const(char)[] h1, const(char)[] h2) {
bool compareHash(const(char)[] h1, const(char)[] h2)
{
import std.digest : secureEqual;
import std.uni : asLowerCase;
return secureEqual(h1.asLowerCase, h2.asLowerCase);
Expand Down Expand Up @@ -320,7 +327,7 @@ int processFile(string path)
++count;
if (entry.isDir)
{
printError(5, "'%s': Is a directory", file);
printWarning("'%s': Is a directory", file);
continue;
}

Expand Down Expand Up @@ -395,7 +402,7 @@ int processList(string listPath)
if (formattedRead(line, "%s %s", expected, file) != 2)
{
++statErrors;
printError(11, "Formatting error at line %u", currentLine);
printWarning("Could not get hash at line %u", currentLine);
continue;
}
break;
Expand All @@ -404,7 +411,7 @@ int processList(string listPath)
if (formattedRead(line, "%s(%s) = %s", hash, file, expected) != 3)
{
++statErrors;
printError(12, "Formatting error at line %u", currentLine);
printWarning("Could not get hash at line %u", currentLine);
continue;
}

Expand All @@ -422,10 +429,10 @@ int processList(string listPath)
}
}

printError(13, "Hash tag not found at line %u", currentLine);
printWarning("Unknown hash tag at line %u", currentLine);
continue;
case sri:
throw new Exception("SRI is not supported in file checks");
return printError(15, "SRI is not supported in file checks");
}

L_ENTRY_HASH:
Expand Down

0 comments on commit f5cb4d8

Please sign in to comment.