SigNoz/signoz · error

CODE_INVALID_INPUT

CODE_INVALID_INPUT

Error message

failed to parse duration text

What it means

ParseTextDuration converts a human-readable duration string into a TextDuration (which preserves the original text for round-tripping). It calls time.ParseDuration directly, so only Go-native syntax is accepted: ns, us/µs, ms, s, m, h with optional decimals; anything else fails with CODE_INVALID_INPUT.

Source

Thrown at pkg/valuer/text_duration.go:26

	"github.com/SigNoz/signoz/pkg/errors"
)

var _ Valuer = (*TextDuration)(nil)

// TextDuration preserves the human-readable duration text as provided by the input.
// It keeps the raw JSON bytes so serialization does not normalize values like
// "90m" into "1h30m0s".
type TextDuration struct {
	text  string
	value time.Duration
}

// ParseTextDuration parses a human-readable duration string.
// This preserves the raw text so that it can be serialized back to JSON.
func ParseTextDuration(s string) (TextDuration, error) {
	d, err := time.ParseDuration(s)
	if err != nil {
		return TextDuration{}, errors.Wrap(err, errors.TypeInvalidInput, errors.CodeInvalidInput, "failed to parse duration text")
	}
	return TextDuration{text: s, value: d}, nil
}

// MustParseTextDuration parses a human-readable duration string, preserving
// the raw text and panics if an error occurs.
func MustParseTextDuration(s string) TextDuration {
	d, err := ParseTextDuration(s)
	if err != nil {
		panic(err)
	}
	return d
}

// Duration returns the [time.Duration] type.
func (d TextDuration) Duration() time.Duration {
	return d.value
}

View on GitHub (pinned to 5069bf80b0)

Solutions

  1. Convert day/week values to hours: "7d" → "168h", "1w" → "168h"
  2. Use compound Go syntax: "1h30m", "0.5h", "90s"
  3. Default omitted fields to a valid literal like "0s" instead of empty string

Example fix

// before
interval := "7d"
d, err := valuer.ParseTextDuration(interval)

// after
interval := "168h"
d, err := valuer.ParseTextDuration(interval)
Defensive patterns

Strategy: validation

Validate before calling

if _, err := time.ParseDuration(s); err != nil {
    s = convertHumanDuration(s) // e.g. "7d" -> "168h"
}
td, err := valuer.ParseTextDuration(s)

Type guard

func isParsableDuration(s string) bool { _, err := time.ParseDuration(s); return err == nil }

Try / catch

td, err := valuer.ParseTextDuration(s)
if err != nil {
    td = valuer.MustParseTextDuration("1h") // safe default
}

Prevention

When it happens

Trigger: Calling ParseTextDuration (or JSON-unmarshaling a field typed TextDuration) with strings like "1d", "30 minutes", "PT1H", "" or "1w". Note GetEvalDelay and other callers forward user/API input here, so these surface from query params and JSON bodies.

Common situations: API clients assuming day/week units exist ("7d" is the classic Prometheus-style value that Go rejects); empty-string defaults from omitted config fields; ISO-8601 durations from other systems.

Understand the failure class

Related errors


AI-assisted analysis of SigNoz/signoz@5069bf80b0 (2026-08-28). Data as JSON: /api/errors/de6d916dd92ad99a. Report an issue: GitHub.