All YAML exceptions now keep track of file and line they've been
thrown at, making debugging easier.
This commit is contained in:
parent
34b11405d4
commit
8360da733d
|
@ -32,12 +32,7 @@ package:
|
||||||
*/
|
*/
|
||||||
class ComposerException : MarkedYAMLException
|
class ComposerException : MarkedYAMLException
|
||||||
{
|
{
|
||||||
this(string context, Mark contextMark, string problem, Mark problemMark)
|
mixin MarkedExceptionCtors;
|
||||||
{
|
|
||||||
super(context, contextMark, problem, problemMark);
|
|
||||||
}
|
|
||||||
|
|
||||||
this(string problem, Mark problemMark){super(problem, problemMark);}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///Composes YAML documents from events provided by a Parser.
|
///Composes YAML documents from events provided by a Parser.
|
||||||
|
|
|
@ -43,9 +43,10 @@ class ConstructorException : YAMLException
|
||||||
* start = Start position of the error context.
|
* start = Start position of the error context.
|
||||||
* end = End position of the error context.
|
* end = End position of the error context.
|
||||||
*/
|
*/
|
||||||
this(string msg, Mark start, Mark end)
|
this(string msg, Mark start, Mark end, string file = __FILE__, int line = __LINE__)
|
||||||
{
|
{
|
||||||
super(msg ~ "\nstart:" ~ start.toString() ~ "\nend:" ~ end.toString());
|
super(msg ~ "\nstart:" ~ start.toString() ~ "\nend:" ~ end.toString(),
|
||||||
|
file, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,12 +37,15 @@ import dyaml.util;
|
||||||
|
|
||||||
package:
|
package:
|
||||||
|
|
||||||
///Exception thrown at Emitter errors.
|
/**
|
||||||
|
* Exception thrown at Emitter errors.
|
||||||
|
*
|
||||||
|
* See_Also:
|
||||||
|
* YAMLException
|
||||||
|
*/
|
||||||
class EmitterException : YAMLException
|
class EmitterException : YAMLException
|
||||||
{
|
{
|
||||||
public:
|
mixin ExceptionCtors;
|
||||||
///Construct an EmitterException with specified message.
|
|
||||||
this(string msg){super(msg);}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Stores results of analysis of a scalar, determining e.g. what scalar style to use.
|
//Stores results of analysis of a scalar, determining e.g. what scalar style to use.
|
||||||
|
|
|
@ -17,8 +17,11 @@ import std.string;
|
||||||
class YAMLException : Exception
|
class YAMLException : Exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
///Construct a YAMLException with specified message.
|
///Construct a YAMLException with specified message, and position where it was thrown.
|
||||||
this(string msg){super(msg);}
|
this(string msg, string file = __FILE__, int line = __LINE__)
|
||||||
|
{
|
||||||
|
super(msg, file, line);
|
||||||
|
}
|
||||||
|
|
||||||
package:
|
package:
|
||||||
//Set name of the file that was being processed when this exception was thrown.
|
//Set name of the file that was being processed when this exception was thrown.
|
||||||
|
@ -59,17 +62,45 @@ package:
|
||||||
abstract class MarkedYAMLException : YAMLException
|
abstract class MarkedYAMLException : YAMLException
|
||||||
{
|
{
|
||||||
//Construct a MarkedYAMLException with specified context and problem.
|
//Construct a MarkedYAMLException with specified context and problem.
|
||||||
this(string context, Mark contextMark, string problem, Mark problemMark)
|
this(string context, Mark contextMark, string problem, Mark problemMark,
|
||||||
|
string file = __FILE__, int line = __LINE__)
|
||||||
{
|
{
|
||||||
string msg = context ~ '\n';
|
string msg = context ~ '\n';
|
||||||
if(contextMark != problemMark){msg ~= contextMark.toString() ~ '\n';}
|
if(contextMark != problemMark){msg ~= contextMark.toString() ~ '\n';}
|
||||||
msg ~= problem ~ '\n' ~ problemMark.toString() ~ '\n';
|
msg ~= problem ~ '\n' ~ problemMark.toString() ~ '\n';
|
||||||
super(msg);
|
super(msg, file, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Construct a MarkedYAMLException with specified problem.
|
//Construct a MarkedYAMLException with specified problem.
|
||||||
this(string problem, Mark problemMark)
|
this(string problem, Mark problemMark, string file = __FILE__, int line = __LINE__)
|
||||||
{
|
{
|
||||||
super(problem ~ '\n' ~ problemMark.toString());
|
super(problem ~ '\n' ~ problemMark.toString(), file, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///Constructors of YAML exceptions are mostly the same, so we use a mixin.
|
||||||
|
template ExceptionCtors()
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
this(string msg, string file = __FILE__, int line = __LINE__)
|
||||||
|
{
|
||||||
|
super(msg, file, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///Constructors of marked YAML exceptions are mostly the same, so we use a mixin.
|
||||||
|
template MarkedExceptionCtors()
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
this(string context, Mark contextMark, string problem, Mark problemMark,
|
||||||
|
string file = __FILE__, int line = __LINE__)
|
||||||
|
{
|
||||||
|
super(context, contextMark, problem, problemMark,
|
||||||
|
file, line);
|
||||||
|
}
|
||||||
|
|
||||||
|
this(string problem, Mark problemMark, string file = __FILE__, int line = __LINE__)
|
||||||
|
{
|
||||||
|
super(problem, problemMark, file, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,9 +37,9 @@ class NodeException : YAMLException
|
||||||
* Params: msg = Error message.
|
* Params: msg = Error message.
|
||||||
* start = Start position of the node.
|
* start = Start position of the node.
|
||||||
*/
|
*/
|
||||||
this(string msg, Mark start)
|
this(string msg, Mark start, string file = __FILE__, int line = __LINE__)
|
||||||
{
|
{
|
||||||
super(msg ~ "\nNode at:" ~ start.toString());
|
super(msg ~ "\nNode at:" ~ start.toString(), file, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,12 +96,7 @@ package:
|
||||||
*/
|
*/
|
||||||
class ParserException : MarkedYAMLException
|
class ParserException : MarkedYAMLException
|
||||||
{
|
{
|
||||||
this(string context, Mark contextMark, string problem, Mark problemMark)
|
mixin MarkedExceptionCtors;
|
||||||
{
|
|
||||||
super(context, contextMark, problem, problemMark);
|
|
||||||
}
|
|
||||||
|
|
||||||
this(string problem, Mark problemMark){super(problem, problemMark);}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///Generates events from tokens provided by a Scanner.
|
///Generates events from tokens provided by a Scanner.
|
||||||
|
|
|
@ -27,7 +27,10 @@ package:
|
||||||
///Exception thrown at Reader errors.
|
///Exception thrown at Reader errors.
|
||||||
class ReaderException : YAMLException
|
class ReaderException : YAMLException
|
||||||
{
|
{
|
||||||
this(string msg){super("Error reading YAML stream: " ~ msg);}
|
this(string msg, string file = __FILE__, int line = __LINE__)
|
||||||
|
{
|
||||||
|
super("Error reading YAML stream: " ~ msg, file, line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///Reads data from a stream and converts it to UTF-32 (dchar) data.
|
///Reads data from a stream and converts it to UTF-32 (dchar) data.
|
||||||
|
|
|
@ -30,9 +30,7 @@ import dyaml.tag;
|
||||||
///Exception thrown on Representer errors.
|
///Exception thrown on Representer errors.
|
||||||
class RepresenterException : YAMLException
|
class RepresenterException : YAMLException
|
||||||
{
|
{
|
||||||
public:
|
mixin ExceptionCtors;
|
||||||
///Construct an RepresenterException with specified message.
|
|
||||||
this(string msg){super(msg);}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///Used to represent YAML nodes various data types into scalar/sequence/mapping nodes ready for output.
|
///Used to represent YAML nodes various data types into scalar/sequence/mapping nodes ready for output.
|
||||||
|
|
|
@ -61,12 +61,7 @@ package:
|
||||||
*/
|
*/
|
||||||
class ScannerException : MarkedYAMLException
|
class ScannerException : MarkedYAMLException
|
||||||
{
|
{
|
||||||
this(string context, Mark contextMark, string problem, Mark problemMark)
|
mixin MarkedExceptionCtors;
|
||||||
{
|
|
||||||
super(context, contextMark, problem, problemMark);
|
|
||||||
}
|
|
||||||
|
|
||||||
this(string problem, Mark problemMark){super(problem, problemMark);}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///Generates tokens from data provided by a Reader.
|
///Generates tokens from data provided by a Reader.
|
||||||
|
|
Loading…
Reference in a new issue