fix: TypeError: P.substring is not a function in grafana mappers#4974
Open
cursor[bot] wants to merge 2 commits into
Open
fix: TypeError: P.substring is not a function in grafana mappers#4974cursor[bot] wants to merge 2 commits into
cursor[bot] wants to merge 2 commits into
Conversation
Replace unsafe .substring() calls on configuration.text/comment values with the safe truncate() utility from safeMappers. When the API returns a non-string value (number, object, array) for these fields, calling .substring() throws TypeError: P.substring is not a function. Affected files: - grafana/create_silence.ts (configuration.comment) - grafana/create_annotation.ts (configuration.text in 2 places) - grafana/list_annotations.ts (configuration.text + truncateText helper) - grafana/incident_shared.ts (truncate now accepts unknown) Adds regression tests covering non-string configuration values. This is a follow-up to #4005, which fixed the same class of bug for other mappers but missed the grafana annotation/silence/incident files.
|
👋 Commands for maintainers:
|
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.
Summary
Fix
TypeError: P.substring is not a functionSentry crash caused by calling.substring()directly onconfiguration.text/configuration.commentvalues inside several Grafana canvas-node mappers. When the API returns a non-string value (number, object, array) for these fields,.substring()throws and the canvas degrades to theCan't displayfallback.This is a follow-up to #4005, which introduced the safe
truncate()utility insafeMappers.tsand migrated most mappers to use it — but missed the Grafana annotation / silence / incident files.Sentry
TypeError: P.substring is not a function?(assets/index-D-SN1A9B)(minified bundle,P= some non-string config value)Changes
grafana/create_silence.ts— usetruncate(configuration.comment, 60)instead ofconfiguration.comment.substring(...).grafana/create_annotation.ts— usetruncate(configuration.text, 80 / 50)in bothgetExecutionDetailsand the metadata builder.grafana/list_annotations.ts— usetruncate(configuration.text, 50 / 80)and replace the localtruncateText(value: string, …)helper (which would throw on non-strings) with the safetruncate()fromsafeMappers.grafana/incident_shared.ts— relax the localtruncate(value)to acceptunknownand coerce to string before calling.substring, mirroringsafeMappers.truncate.Tests
grafana/annotations.spec.tswith regression tests forcreateAnnotationMapperandlistAnnotationsMapperexercising non-stringconfiguration.textand a non-stringlatest.textin output payloads.grafana/silences_and_incident_shared.spec.tscoveringcreateSilenceMapperwith non-stringconfiguration.comment(number / object) and theincident_shared.truncatehelper for nullish, primitive, and object inputs.Notes
createSafeComponentMapper, but per the precedent in fix: TypeError: z.substring is not a function #4005 the proper fix is to prevent the throw entirely so the node renders normally instead of falling back toCan't display.