8000 Fix uncaught exception on errors.js when 'bugs' field is missing from package.json by EricGeigerQ · Pull Request #984 · tulios/kafkajs · GitHub
[go: up one dir, main page]

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

Fix uncaught exception on errors.js when 'bugs' field is missing from package.json #984

Merged
merged 1 commit into from
Dec 11, 2020
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
9 changes: 6 additions & 3 deletions src/errors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const pkgJson = require('../package.json')
const { bugs } = pkgJson

class KafkaJSError extends Error {
constructor(e, { retriable = true } = {}) {
Expand Down Expand Up @@ -195,16 +196,18 @@ class KafkaJSDeleteTopicRecordsError extends KafkaJSError {
}
}

const issueUrl = pkgJson.bugs.url
const issueUrl = bugs ? bugs.url : null

class KafkaJSInvariantViolation extends KafkaJSNonRetriableError {
constructor(e) {
const message = e.message || e
super(`Invariant violated: ${message}. This is likely a bug and should be reported.`)
this.name = 'KafkaJSInvariantViolation'

const issueTitle = encodeURIComponent(`Invariant violation: ${message}`)
this.helpUrl = `${issueUrl}/new?assignees=&labels=bug&template=bug_report.md&title=${issueTitle}`
if (issueUrl !== null) {
const issueTitle = encodeURIComponent(`Invariant violation: ${message}`)
this.helpUrl = `${issueUrl}/new?assignees=&labels=bug&template=bug_report.md&title=${issueTitle}`
}
}
}

Expand Down
0