@@ -294,8 +294,7 @@ export function runTransforms(content, flist, ...funcArgs) {
294
294
} catch ( e ) {
295
295
const msg = `call to \`${ meth } ()\` failed with: ${ e } .` ;
296
296
const hint = "See developer console for stack trace." ;
297
- showWarning ( msg , "utils/runTransforms" , { hint } ) ;
298
- console . error ( e ) ;
297
+ showWarning ( msg , "utils/runTransforms" , { hint, cause : e } ) ;
299
298
}
300
299
}
301
300
}
@@ -850,7 +849,7 @@ export class RespecError extends Error {
850
849
* @param {Parameters<typeof showError>[2] & { isWarning: boolean } } options
851
850
*/
852
851
constructor ( message , plugin , options ) {
853
- super ( message ) ;
852
+ super ( message , { ... ( options . cause && { cause : options . cause } ) } ) ;
854
853
const name = options . isWarning ? "ReSpecWarning" : "ReSpecError" ;
855
854
Object . assign ( this , { message, plugin, name, ...options } ) ;
856
855
if ( options . elements ) {
@@ -864,7 +863,23 @@ export class RespecError extends Error {
864
863
const { message, name, stack } = this ;
865
864
// @ts -expect-error https://github.com/microsoft/TypeScript/issues/26792
866
865
const { plugin, hint, elements, title, details } = this ;
867
- return { message, name, plugin, hint, elements, title, details, stack } ;
866
+ return {
867
+ message,
868
+ name,
869
+ plugin,
870
+ hint,
871
+ elements,
872
+ title,
873
+ details,
874
+ stack,
875
+ ...( this . cause instanceof Error && {
876
+ cause : {
877
+ name : this . cause . name ,
878
+ message : this . cause . message ,
879
+ stack : this . cause . stack ,
880
+ } ,
881
+ } ) ,
882
+ } ;
868
883
}
869
884
}
870
885
@@ -876,6 +891,7 @@ export class RespecError extends Error {
876
891
* @param {HTMLElement[] } [options.elements] Offending elements.
877
892
* @param {string } [options.title] Title attribute for offending elements. Can be a shorter form of the message.
878
893
* @param {string } [options.details] Any further details/context.
894
+ * @param {Error } [options.cause] The error that caused this one.
879
895
*/
880
896
export function showError ( message , pluginName , options = { } ) {
881
897
const opts = { ...options , isWarning : false } ;
@@ -890,6 +906,7 @@ export function showError(message, pluginName, options = {}) {
890
906
* @param {HTMLElement[] } [options.elements] Offending elements.
891
907
* @param {string } [options.title] Title attribute for offending elements. Can be a shorter form of the message.
892
908
* @param {string } [options.details] Any further details/context.
909
+ * @param {Error } [options.cause] The error that caused this one.
893
910
*/
894
911
export function showWarning ( message , pluginName , options = { } ) {
895
912
const opts = { ...options , isWarning : true } ;
0 commit comments