%mathpiper,def="DumpErrors"

/// print all errors and clear the tableau
DumpErrors() <--
[
	Local(error'object, error'word);
	CheckErrorTableau();
	ForEach(error'object, GetErrorTableau())
	[	// error'object might be e.g. {"critical", {"bad bad", -1000}}
		If(
			IsList(error'object),
			[
				If( // special case: error class "warning"
					Length(error'object) > 0 And error'object[1] = "warning",
					[
						error'word := "Warning";
						error'object[1] := "";	// don't print the word "warning" again
					],
					error'word := "Error: "	// important hack: insert ": " here but not after "Warning"
				);

				If(	// special case: {"error'class", True}
					Length(error'object)=2 And error'object[2]=True,
					Echo(error'word, error'object[1]),
					[
						Echo(error'word, error'object[1], ": ",
							PrintList(Rest(error'object)));
					]
				);
			],
			// error'object is not a list: just print it
			Echo("Error: ", error'object)
		);
	];
	ClearErrors();
];

%/mathpiper




%mathpiper_docs,name="DumpErrors",categories="Programmer Functions;Error Reporting",access="private"
*CMD DumpErrors --- simple error handlers
*STD
*CALL
	DumpErrors()

*DESC

{DumpErrors} is a simple error handler for the global error reporting mechanism. It prints all errors posted using {Assert} and clears the error tableau.

*SEE Assert, IsError, ClearErrors

%/mathpiper_docs