Assertion Error
Vino.B via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Sep 13 00:39:46 PDT 2017
On Tuesday, 12 September 2017 at 21:01:26 UTC, Moritz Maxeiner
wrote:
> On Tuesday, 12 September 2017 at 19:44:19 UTC, vino wrote:
>> Hi All,
>>
>> I have a small piece of code which executes perfectly 8 out of
>> 10 times, very rarely it throws an assertion error, so is
>> there a way to find which line of code is causing this error.
>
> You should be getting the line number as part of the crash,
> like here:
>
> --- test.d ---
> void main(string[] args)
> {
> assert(args.length > 1);
> }
> --------------
>
> -----------------
> $ dmd -run test.d
>
> core.exception.AssertError at test.d(3): Assertion failure
> [Stack trace]
> -----------------
>
> If you don't what are the steps to reproduce?
Hi Max,
I tried to run the code for at least 80+ time the code ran
without any issue, will let you know in case if I hit the same
issue in feature, Below is the piece of code, plese do let me
know if you find any issue with the below code.
Program Code:
import core.stdc.stdlib: exit;
import std.algorithm: all, among, filter, map, setDifference,
sort, uniq, each, joiner;
import std.array: appender, join;
import std.container.array;
import std.conv: to;
import std.datetime.systime: Clock, days, SysTime;
import std.file: SpanMode, dirEntries, exists, isFile, mkdir,
remove, rmdirRecurse;
import std.getopt;
import std.parallelism: parallel, task, taskPool;
import std.path: absolutePath, baseName, dirName,
isValidFilename, isValidPath, globMatch;
import std.range: empty, zip, chain, chunks;
import std.stdio: File, writefln, writeln;
import std.string: chomp, chop, isNumeric, split, strip;
import std.typecons: tuple, Tuple;
import std.uni: isAlpha, toLower, isWhite;
import std.conv;
auto coSizeDirList (string FFs, int SizeDir) {
int subdirTotal;
int subdirTotalGB;
Array!string Subdir;
Array!string Subsize;
Array!string Result;
auto dFiles = Array!string ((dirEntries(FFs,
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));
foreach (d; dFiles[]) {
auto SdFiles = Array!ulong(dirEntries(d,
SpanMode.depth).map!(a => a.size));
foreach(f; SdFiles[]) { subdirTotal += f; }
subdirTotalGB = (subdirTotal/1024/1024);
if (subdirTotalGB > SizeDir) { Result ~= d; Result ~=
to!string(subdirTotalGB); }
subdirTotal = 0;
}
return Result;
}
void ptSizeDirList (Array!string SizeDirlst, int SizeDir) {
alias DirSizeList = typeof(coSizeDirList(string.init, int.init));
auto MSresult = taskPool.workerLocalStorage!DirSizeList();
foreach (string Fs; parallel(SizeDirlst[0 .. $], 1)) {
auto FFs = Fs.strip;
auto MSizeDirList = task(&coSizeDirList, FFs, SizeDir);
MSizeDirList.executeInNewThread();
auto MSizeDirListData = MSizeDirList.workForce;
MSresult.get ~= MSizeDirListData;
}
foreach(i; MSresult.toRange)
chain(i[]).chunks(2).each!(e => writefln!"%-60s %s"(e[0],
e[1]));
}
void main () {
auto SizeDirlst = Array!string( "C:\\Temp\\TEST2\\BACKUP",
"C:\\Temp\\TEST2\\EXPORT", "C:\\Temp\\TEST2\\PROD_TEAM",
"C:\\Temp\\TEST2\\TEAM", "C:\\Temp\\TEST3\\BACKUP",
"C:\\Temp\\TEST3\\EXPORT" );
int SizeDir = 10;
ptSizeDirList(SizeDirlst, SizeDir);
}
From,
Vino.B
More information about the Digitalmars-d-learn
mailing list