From 3227d2cc7824409e16976096b45c2d18072c59f9 Mon Sep 17 00:00:00 2001 From: Dag Andersen Date: Thu, 26 Mar 2026 09:07:55 +0100 Subject: [PATCH] Fix | Show helpful message when --max-diff-length is too small to display diff --- pkg/diff/markdown.go | 7 ++++++- pkg/diff/markdown_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/pkg/diff/markdown.go b/pkg/diff/markdown.go index 6ce888de..cbd263ef 100644 --- a/pkg/diff/markdown.go +++ b/pkg/diff/markdown.go @@ -191,7 +191,12 @@ func (m *MarkdownOutput) printDiff(maxDiffMessageCharCount uint) string { } if sectionsDiff.Len() == 0 { - sectionsDiff.WriteString("No changes found") + if len(m.sections) > 0 { + sectionsDiff.WriteString(fmt.Sprintf("⚠️ Changes were found but `--max-diff-length` (%d) is too small to display them. Increase the value or check the HTML output instead.", maxDiffMessageCharCount)) + log.Warn().Msgf("🚨 --max-diff-length (%d) is too small to display any diff content. Increase the value or use the HTML output instead.", maxDiffMessageCharCount) + } else { + sectionsDiff.WriteString("No changes found") + } } output = strings.ReplaceAll(output, "%info_box%", m.statsInfo.String()) diff --git a/pkg/diff/markdown_test.go b/pkg/diff/markdown_test.go index 2fb77280..b88a3fb6 100644 --- a/pkg/diff/markdown_test.go +++ b/pkg/diff/markdown_test.go @@ -212,6 +212,35 @@ func TestMarkdownOutput_PrintDiff(t *testing.T) { "⚠️⚠️⚠️ Diff exceeds max length", }, }, + { + name: "Extremely small max-diff-length shows helpful message instead of no changes found", + output: MarkdownOutput{ + title: "Tiny Diff", + summary: "Some changes", + sections: []MarkdownSection{ + { + appName: "My App", + filePath: "path/to/app.yaml", + appURL: "", + resources: []ResourceSection{ + {Header: "@@ Application modified: My App @@", Content: "+ new line\n- old line\n"}, + }, + }, + }, + statsInfo: StatsInfo{ + ApplicationCount: 1, + }, + }, + maxSize: 3, // Extremely small - like the user in issue #392 + maxDiffMessageCharCount: 3, + expectedContains: []string{ + "too small to display them", + "--max-diff-length", + }, + expectedNotContains: []string{ + "No changes found", + }, + }, { name: "Truncated output shows warning", output: MarkdownOutput{