pulumi/pulumi · error
failed to parse --before as duration or timestamp: %w
Error message
failed to parse --before as duration or timestamp: %w
What it means
The --before flag of `pulumi logs remove` (pkg/cmd/pulumi/logs/remove.go:139) accepts a Go duration (e.g. '24h') or a timestamp (RFC3339, date, or Unix). The value is passed to parseSince (pkg/cmd/pulumi/logs/logs.go:226), which uses the moby-derived getTimestamp parser; when neither format matches, the underlying error is wrapped with this message.
Source
Thrown at pkg/cmd/pulumi/logs/remove.go:139
if !all && before == "" && stackName == "" {
if !cmdutil.Interactive() {
return nil, errors.New(
"cannot prompt for a log file in non-interactive mode; " +
"pass --all, --before, or --stack")
}
entry, err := chooseLogToRemove(logsDir)
if err != nil {
return nil, err
}
return []logEntry{entry}, nil
}
var beforeTime *time.Time
if before != "" {
var err error
beforeTime, err = parseSince(before, time.Now())
if err != nil {
return nil, fmt.Errorf("failed to parse --before as duration or timestamp: %w", err)
}
}
entries, err := listLogs(logsDir)
if err != nil {
return nil, err
}
return filterLogs(entries, stackName, beforeTime), nil
}
func filterLogs(entries []logEntry, stackName string, beforeTime *time.Time) []logEntry {
var matches []logEntry
for _, e := range entries {
if stackName != "" && e.stack != stackName {
continue
}
if beforeTime != nil && !e.timestamp.Before(*beforeTime) {View on GitHub (pinned to 793f7b2e16)
Solutions
- Use a Go duration such as 24h, 72h, or 30m (no 'd' or 'w' units)
- Use an absolute timestamp: RFC3339 (2026-01-01T00:00:00Z), a plain date (2026-01-01), or a Unix epoch value
- Quote the value in the shell if it contains spaces or special characters
- Verify with `pulumi logs --since <same-value>` which accepts the identical format and shows the same parse error
Example fix
# before pulumi logs remove --before 30d # after pulumi logs remove --before 720h # 30 days as a Go duration # or pulumi logs remove --before 2026-01-01
Defensive patterns
Strategy: validation
Validate before calling
# Go-side pre-validation using the same semantics
if _, err := time.ParseDuration(v); err != nil {
if _, err2 := time.Parse(time.RFC3339, v); err2 != nil {
if _, _, err3 := time.Parse("2006-01-02", v); err3 != nil {
return fmt.Errorf("--before must be a Go duration (720h) or timestamp: %v", v)
}
}
} Prevention
- Use only Go duration units (s, m, h) — 1d/1w are invalid; convert days to hours
- Prefer absolute dates like 2026-01-01 for anything older than a few days
- Smoke-test the value with `pulumi logs --since <value>` first
When it happens
Trigger: `pulumi logs remove --before <value>` where value fails time.ParseDuration and all timestamp layouts: e.g. --before 24H (uppercase), --before 1d (Go durations have no days), --before yesterday, --before "Jan 1 2026", or a negative range with hyphens that can't parse.
Common situations: Copying '1d' or '2w' from other CLIs that accept day/week units; locale-formatted dates; quotes stripped by shell leaving ambiguous values like 2026-13-45; forgetting that durations are Go-style (h/m/s only).
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- unknown output format %q
- --once must be an ISO 8601 / RFC 3339 timestamp: %w
- --once must be a timestamp in the future
- --once must be an ISO 8601 / RFC 3339 timestamp: %w
- --once must be a timestamp in the future
AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31).
Data as JSON: /api/errors/90c9a674f0e0b879.
Report an issue: GitHub.