1 module tagion.actor.exceptions; 2 3 import std.traits; 4 import std.exception; 5 import tagion.basic.tagionexceptions : TagionException; 6 7 import tagion.hibon.HiBONRecord; 8 import tagion.hibon.HiBON; 9 import tagion.hibon.Document; 10 import std.conv; 11 12 // Fake Throwable hibon record constructor 13 @recordType("throwable") 14 struct _Throwable { 15 string msg; 16 string file; 17 ulong line; 18 string trace; 19 mixin HiBONRecord!(q{ 20 this(const Throwable t) @trusted { 21 msg = t.msg; 22 file = t.file; 23 line = t.line; 24 trace = t.info.to!string; 25 } 26 }); 27 } 28 29 immutable struct TaskFailure { 30 string task_name; 31 Throwable throwable; 32 33 const(Document) toDoc() @safe const { 34 auto hibon = new HiBON; 35 hibon[(GetLabel!task_name).name] = task_name; 36 hibon[(GetLabel!throwable).name] = _Throwable(throwable).toDoc; 37 return Document(hibon); 38 } 39 } 40 41 /++ 42 This function set the taskname set by the logger 43 The version LOGGER must be enabled for this to work 44 The function is used to send the exception to the task owner ownerTid 45 Returns: 46 The immutable version of the Exception 47 +/ 48 @trusted 49 static immutable(TaskFailure) taskException(const(Throwable) e) nothrow { //if (is(T:Throwable) && !is(T:TagionExceptionInterface)) { 50 import tagion.logger.Logger; 51 52 return immutable(TaskFailure)(log.task_name, cast(immutable) e); 53 } 54 55 /** 56 Exception type used by tagion.actor.actor 57 */ 58 @safe class ActorException : TagionException { 59 this(string msg, string file = __FILE__, size_t line = __LINE__) pure { 60 super(msg, file, line); 61 } 62 } 63 64 /// Exception sent when the actor gets a message that it doesn't handle 65 @safe class UnknownMessage : ActorException { 66 this(immutable(char)[] msg, string file = __FILE__, size_t line = __LINE__) pure { 67 super(msg, file, line); 68 } 69 } 70 71 // Exception when the actor fails to start or stop 72 @safe class RunFailure : ActorException { 73 this(immutable(char)[] msg, string file = __FILE__, size_t line = __LINE__) pure { 74 super(msg, file, line); 75 } 76 }