Skip to content

fix: TypeError: P.substring is not a function in grafana mappers#4974

Open
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/agent-fabe2503
Open

fix: TypeError: P.substring is not a function in grafana mappers#4974
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/agent-fabe2503

Conversation

@cursor
Copy link
Copy Markdown
Contributor

@cursor cursor Bot commented May 24, 2026

Summary

Fix TypeError: P.substring is not a function Sentry crash caused by calling .substring() directly on configuration.text / configuration.comment values 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 the Can't display fallback.

This is a follow-up to #4005, which introduced the safe truncate() utility in safeMappers.ts and migrated most mappers to use it — but missed the Grafana annotation / silence / incident files.

Sentry

Changes

  • grafana/create_silence.ts — use truncate(configuration.comment, 60) instead of configuration.comment.substring(...).
  • grafana/create_annotation.ts — use truncate(configuration.text, 80 / 50) in both getExecutionDetails and the metadata builder.
  • grafana/list_annotations.ts — use truncate(configuration.text, 50 / 80) and replace the local truncateText(value: string, …) helper (which would throw on non-strings) with the safe truncate() from safeMappers.
  • grafana/incident_shared.ts — relax the local truncate(value) to accept unknown and coerce to string before calling .substring, mirroring safeMappers.truncate.

Tests

  • Extend grafana/annotations.spec.ts with regression tests for createAnnotationMapper and listAnnotationsMapper exercising non-string configuration.text and a non-string latest.text in output payloads.
  • New grafana/silences_and_incident_shared.spec.ts covering createSilenceMapper with non-string configuration.comment (number / object) and the incident_shared.truncate helper for nullish, primitive, and object inputs.

Notes

  • These mappers are still wrapped by 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 to Can't display.
Open in Web Open in Cursor 

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.
@superplanehq-integration
Copy link
Copy Markdown

👋 Commands for maintainers:

  • /sp start - Start an ephemeral machine (takes ~30s)
  • /sp stop - Stop a running machine (auto-executed on pr close)

@forestileao forestileao self-assigned this May 25, 2026
@forestileao forestileao marked this pull request as ready for review May 25, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants