Skip to content

projects defaults show prints nothing in text mode when a project has no defaults #5

Description

@gdameneses

Summary

urlbox projects defaults show <project> prints zero bytes in text mode when the project has no default options. The JSON envelope carries a perfectly good summary; text mode drops it.

Reproduce

  1. Pick any project with no defaultOptions set.

  2. Run it in text mode:

    urlbox projects defaults show <project> --output-format text

Expected

A line saying there are no defaults — the summary the envelope already contains.

Actual

Nothing. Exit code 0, empty stdout:

$ urlbox projects defaults show <project> --output-format text | wc -c
0

JSON mode has the message all along:

{
  "ok": true,
  "command": "projects defaults show",
  "data": {"defaults": {}, "project": "proj_xxx"},
  "summary": "0 default options on proj_xxx"
}

A command that prints nothing and exits 0 is indistinguishable from a hang or a silently broken subcommand.

Cause

Two behaviours combine:

  • internal/output/format.go:60 prints the summary only when there is no view:

    if env.Summary != "" && (!env.OK || env.view == nil) {
  • internal/output/render.go:74RenderKV returns early on an empty slice ("An empty pairs writes nothing").

runProjectsDefaultsShow called env.SetKV(...) unconditionally, so with zero defaults the view was non-nil (suppressing the summary) but rendered nothing. Net result: no output at all.

Fix

Attach the view only when there is something in it, so the existing summary survives — internal/cmd/projects.go:

	// A viewless envelope keeps its summary in text mode; an empty KV view
	// renders nothing at all, so a project with no defaults would print
	// zero bytes. Only attach the view when there is something to show.
	if pairs := optionsKVPairs(defaults); len(pairs) > 0 {
		env.SetKV(pairs)
	}

Text mode then prints 0 default options on proj_xxx. JSON output is unchanged.

Worth checking whether any other command calls SetKV/SetTable with a possibly-empty collection — the same silent-empty-output pattern would apply.

Environment

urlbox 1.2.0 (commit 5530665), Linux.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions