Skip to content

Custom command steps: fails from a terminal since 1.234.0 (ATMOS_FORCE_COLOR forwarded to children) #3757

Done

Description

@mattbnz

Title: Custom command steps: atmos describe ... --format json | jq fails from a terminal since 1.234.0 (ATMOS_FORCE_COLOR forwarded to children)

Describe the Bug

Since v1.234.0, a custom command step that pipes nested atmos describe ... --format json into jq fails whenever the parent atmos runs in a terminal:

jq: parse error: Invalid numeric literal at line 1, column 2

The example components command in the custom commands docs (website/docs/cli/configuration/commands/command/commands.mdx) fails this way.

Custom command steps now receive ATMOS_FORCE_COLOR=true in their environment (added in #3454, commit 146b733, via terminal.ChildColorEnv from OutputModeWriter.ChildEnvironment). The nested atmos describe treats that as "force colour even into pipes" (pkg/utils/highlight_utils.go, where ForceColor bypasses the stdout TTY check), so the JSON written to the pipe is syntax-highlighted with ANSI escapes.

atmos list ... -f json is unaffected; only the highlighted describe output breaks. Running without a TTY (CI, | cat) is also unaffected, because nothing is forwarded then.

Expected Behavior

Machine-readable output (--format json/yaml) piped from a nested atmos inside a custom command step stays plain, as in v1.230.1, while colour still flows through to output that ends up on the terminal.

Steps to Reproduce

atmos.yaml:

base_path: "."
components:
  terraform:
    base_path: components/terraform
stacks:
  base_path: stacks
  included_paths: ["*.yaml"]
  name_template: "{{ .vars.stage }}"
commands:
  - name: components
    description: List components (example from the custom commands docs)
    steps:
      - atmos describe stacks --format json | jq ".[].components.terraform" | jq -s add | jq -r "keys[]"

stacks/dev.yaml:

vars:
  stage: dev
components:
  terraform:
    demo:
      vars: {}

components/terraform/demo/main.tf:

variable "stage" {}

Run atmos components from an interactive terminal. On Linux, script -qec "atmos components" /dev/null provides a PTY non-interactively.

Results (linux/amd64, jq 1.7):

Parent atmos No TTY TTY
1.230.1 demo demo
1.234.1 demo jq: parse error: Invalid numeric literal at line 1, column 2

Inside the step, env | grep FORCE_COLOR prints nothing on 1.230.1 and ATMOS_FORCE_COLOR=true on 1.234.1. The result is the same when the nested atmos binary is held at 1.234.1 and only the parent changes.

Workarounds Tried

  • unset ATMOS_FORCE_COLOR at the start of the step or script works, and restores the 1.230.1 environment.
  • --no-color or NO_COLOR=1 on the nested call works.
  • --file out.json works, because file output is never highlighted.
  • --force-color=false on the nested call does not help; the output is still highlighted.
  • CLICOLOR=0 alongside the forwarded variable does not help.

Suggested Fix

One of:

  • Forward a "colour permitted" hint instead of ATMOS_FORCE_COLOR, so children still detect pipes on their own stdout.
  • Don't syntax-highlight structured --format json/yaml data output when stdout is not a TTY, even when colour is forced.

Environment

  • atmos 1.234.1; pkg/terminal/child_color.go and pkg/utils/highlight_utils.go are unchanged on main as of 6ec7424.
  • Linux amd64
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