Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include potential leaked session stacktraces in error #759

Merged
merged 2 commits into from
Dec 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/session-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,26 @@ export class SessionLeakError extends Error {
}
}

/**
* Error to be thrown when the session pool is exhausted.
*/
export class SessionPoolExhaustedError extends Error {
messages: string[];
constructor(leaks: string[]) {
super(errors.Exhausted);
// Restore error name that was overwritten by the super constructor call.
this.name = SessionPoolExhaustedError.name;
this.messages = leaks;
}
}

/**
* enum to capture errors that can appear from multiple places
*/
const enum errors {
Closed = 'Database is closed.',
Timeout = 'Timeout occurred while acquiring session.',
Exhausted = 'No resources available.',
}

interface SessionInventory {
Expand Down Expand Up @@ -723,8 +737,8 @@ export class SessionPool extends EventEmitter implements SessionPoolInterface {
return this._borrowNextAvailableSession(type);
}

if (this.options.fail!) {
throw new Error('No resources available.');
if (this.isFull && this.options.fail!) {
throw new SessionPoolExhaustedError(this._getLeaks());
}

let removeListener: Function;
Expand Down