1 module dud.pkgdescription.exception; 2 3 import std.array : empty; 4 import std.typecons : nullable, Nullable; 5 import std.format : format; 6 7 import dud.exception; 8 9 @safe pure: 10 11 struct Location { 12 @safe: 13 const string filename; 14 const size_t line; 15 const size_t column; 16 17 string toString() const { 18 return this.filename.empty 19 ? format("Line:%s Column:%s", this.line, 20 this.column) 21 : format("File:%s Line:%s Column:%s", this.filename, this.line, 22 this.column); 23 } 24 } 25 26 string exceptionClassBuilder(string name, string superName) { 27 import std.format : format; 28 29 return q{ 30 class %1$s : %2$s { 31 Nullable!Location location; 32 this(string msg, string file = __FILE__, size_t line = __LINE__) 33 @safe pure nothrow @nogc 34 { 35 super(msg, file, line); 36 } 37 38 this(string msg, string file = __FILE__, size_t line = __LINE__, 39 Throwable next = null) @safe pure nothrow @nogc 40 { 41 super(msg, file, line, next); 42 } 43 44 this(string msg, Location loc, string file = __FILE__, 45 size_t line = __LINE__) @safe pure nothrow @nogc 46 { 47 super(msg, file, line); 48 this.location = nullable(loc); 49 } 50 51 override string toString() { 52 return format("%1$s: %%s %%s", this.msg, 53 (this.location.isNull() ? "" : this.location.toString())); 54 } 55 } 56 }.format(name, superName); 57 } 58 59 mixin(exceptionClassBuilder("DudPkgDescriptionException", "DudException")); 60 mixin(exceptionClassBuilder("KeyNotHandled", "DudPkgDescriptionException")); 61 mixin(exceptionClassBuilder("WrongType", "DudPkgDescriptionException")); 62 mixin(exceptionClassBuilder("WrongTypeJSON", "WrongType")); 63 mixin(exceptionClassBuilder("WrongTypeSDL", "WrongType")); 64 mixin(exceptionClassBuilder("SingleElement", "DudPkgDescriptionException")); 65 mixin(exceptionClassBuilder("NoValues", "DudPkgDescriptionException")); 66 mixin(exceptionClassBuilder("EmptyInput", "DudPkgDescriptionException")); 67 mixin(exceptionClassBuilder("UnexpectedInput", "DudPkgDescriptionException")); 68 mixin(exceptionClassBuilder("ConflictingInput", "DudPkgDescriptionException")); 69 mixin(exceptionClassBuilder("ConflictingOutput", "DudPkgDescriptionException")); 70 mixin(exceptionClassBuilder("UnsupportedAttributes", "DudPkgDescriptionException")); 71 mixin(exceptionClassBuilder("UnknownConfiguration", "DudPkgDescriptionException")); 72 mixin(exceptionClassBuilder("UnknownBuildType", "DudPkgDescriptionException")); 73 mixin(exceptionClassBuilder("ValidationException", "DudPkgDescriptionException")); 74 mixin(exceptionClassBuilder("BuildTypeException", "ValidationException")); 75 mixin(exceptionClassBuilder("EmptyNameException", "ValidationException")); 76 mixin(exceptionClassBuilder("PlatfromSelection", "DudPkgDescriptionException")); 77 mixin(exceptionClassBuilder("DependecyAlreadyPresent", "PlatfromSelection")); 78 mixin(exceptionClassBuilder("ToManyConfigurations", "PlatfromSelection")); 79 mixin(exceptionClassBuilder("InvalidPlatfrom", "PlatfromSelection"));