Skip to content

Commit

Permalink
add Exception previousToStack fallback for none string stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
dasiux committed Apr 14, 2022
1 parent 1d17d78 commit 12c861c
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/es6/Error/Exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,25 @@ export class Exception extends Error {
addPreviousToStack() {

// Only if enabled and stack is a string
if ( this.previousToStack && typeof this.stack === 'string' ) {
if ( this.previousToStack ) {

// There is a previous error and it should be displayable
if ( this.previous
&& ( this.previous instanceof Error || this.previous.toString || typeof this.previous === 'string' ) ) {
if ( typeof this.stack === 'string' ) {

// Add previous prefix
this.stack = this.stack + '\n';
if ( this.previousPrefix ) this.stack = this.stack + this.previousPrefix;
// There is a previous error and it should be displayable
if ( this.previous
&& ( this.previous instanceof Error || this.previous.toString || typeof this.previous === 'string' ) ) {

// Add the previous stack or error to the current stack
this.stack = this.stack + ( typeof this.previous.stack === 'string' ? this.previous.stack : this.previous );
// Add previous prefix
this.stack = this.stack + '\n';
if ( this.previousPrefix ) this.stack = this.stack + this.previousPrefix;

// Add the previous stack or error to the current stack
this.stack = this.stack + ( typeof this.previous.stack === 'string' ? this.previous.stack : this.previous );
}
} else if ( this.previous ) {

// The stack is no string and cannot be modified
window.console.error( this, 'Caused by', this.previous );
}
}
}
Expand Down

0 comments on commit 12c861c

Please sign in to comment.