[Typescript] Pass errors to loggers - #537
Open
Gabe Gorelick (gabegorelick) wants to merge 1 commit into
Open
Conversation
Pass `error` to loggers in the existing `extras` object. Currently, custom loggers do not get passed any underlying error. Fixes confluentinc#334
| } catch (err) { | ||
| /* TODO: we should cry more about this and render the consumer unusable. */ | ||
| this.#logger.error(`Seek error. This is effectively a fatal error: ${err.stack}`); | ||
| this.#logger.error('Seek error. This is effectively a fatal error', |
There was a problem hiding this comment.
We could keep err.stack in the message if we don't want to break consumers. But this library does not consistently include err.stack in log messages.
| if (!this.#connectionError) | ||
| this.#connectionError = err; | ||
| } | ||
| this.#logger.error(`Error: ${err.message}`, this.#createConsumerBindingMessageMetadata()); |
There was a problem hiding this comment.
Notice how we didn't include err.stack here.
| this.#lastConsumedOffsets.set(key, m); | ||
| } catch (e) { | ||
| /* Not much we can do, except log the error. */ | ||
| this.#logger.error(`Consumer encountered error while storing offset. Error details: ${JSON.stringify(e)}`, this.#createConsumerBindingMessageMetadata()); |
There was a problem hiding this comment.
Notice how in this site, the error gets JSON stringified.
Passing the raw error to callers lets this lib be more consistent. The downstream loggers can decide how they want to serialize errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pass
errorto loggers in the existingextrasobject. Currently, custom loggers do not get passed any underlying error.Fixes #334
What
Pass
errorto loggers in the existingextrasobject. Currently, custom loggers do not get passed any underlying error. That makes it impossible for custom loggers to include things likeerror.code,error.cause, etc.Checklist
References
#334
Test & Review
I have been running this patch in production.
Open questions / Follow-ups