Skip to content

Commit f5cb4d8

Browse files
committed
Add proper warnings
1 parent ff888cb commit f5cb4d8

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/main.d

+13-6
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ void trace(string func = __FUNCTION__, A...)(string fmt, A args)
124124
writefln(fmt, args);
125125
}
126126

127+
void printWarning(string func = __FUNCTION__, A...)(string fmt, A args)
128+
{
129+
stderr.write("warning: ");
130+
debug stderr.write("[", func, "] ");
131+
stderr.writefln(fmt, args);
132+
}
127133
int printError(string func = __FUNCTION__, A...)(int code, string fmt, A args)
128134
{
129135
stderr.writef("error: (code %d) ", code);
@@ -208,7 +214,8 @@ unittest
208214
assert(s == 1024 + 102); // 102.4
209215
}
210216

211-
bool compareHash(const(char)[] h1, const(char)[] h2) {
217+
bool compareHash(const(char)[] h1, const(char)[] h2)
218+
{
212219
import std.digest : secureEqual;
213220
import std.uni : asLowerCase;
214221
return secureEqual(h1.asLowerCase, h2.asLowerCase);
@@ -320,7 +327,7 @@ int processFile(string path)
320327
++count;
321328
if (entry.isDir)
322329
{
323-
printError(5, "'%s': Is a directory", file);
330+
printWarning("'%s': Is a directory", file);
324331
continue;
325332
}
326333

@@ -395,7 +402,7 @@ int processList(string listPath)
395402
if (formattedRead(line, "%s %s", expected, file) != 2)
396403
{
397404
++statErrors;
398-
printError(11, "Formatting error at line %u", currentLine);
405+
printWarning("Could not get hash at line %u", currentLine);
399406
continue;
400407
}
401408
break;
@@ -404,7 +411,7 @@ int processList(string listPath)
404411
if (formattedRead(line, "%s(%s) = %s", hash, file, expected) != 3)
405412
{
406413
++statErrors;
407-
printError(12, "Formatting error at line %u", currentLine);
414+
printWarning("Could not get hash at line %u", currentLine);
408415
continue;
409416
}
410417

@@ -422,10 +429,10 @@ int processList(string listPath)
422429
}
423430
}
424431

425-
printError(13, "Hash tag not found at line %u", currentLine);
432+
printWarning("Unknown hash tag at line %u", currentLine);
426433
continue;
427434
case sri:
428-
throw new Exception("SRI is not supported in file checks");
435+
return printError(15, "SRI is not supported in file checks");
429436
}
430437

431438
L_ENTRY_HASH:

0 commit comments

Comments
 (0)