Skip to content

JSON format error message should include the received input value for easier debugging #1110

Description

@surapuramakhil

Description

When passing complex JSON parameters (--nsg-ids, --metadata, --defined-tags, --shape-config, etc.) with invalid JSON, the error message is opaque: it uses the internal Python parameter name (lisp_case) instead of the CLI flag the user typed, and does not echo back the received value.

Steps to Reproduce

NSG_ID="ocid1.networksecuritygroup.oc1..example"
oci compute instance launch ... --nsg-ids "[$NSG_ID]"

Expected Behaviour

The error should include:

  1. The actual CLI flag the user typed (--nsg-ids, not nsg_ids)
  2. The received input value so the user can see what was parsed
  3. A concrete example of valid input
Parameter '--nsg-ids' (received as '[ocid1.networksecuritygroup.oc1..example]')
must be valid JSON. Example: --nsg-ids '["ocid1.networksecuritygroup.oc1..example"]'

Actual Behaviour

Parameter 'nsg_ids' must be in JSON format.
For help with formatting JSON input see our documentation here: https://docs.cloud.oracle.com/iaas/Content/API/SDKDocs/cliusing.htm#ManagingCLIInputandOutput

Problems:

  1. The error says nsg_ids (Python internal name) but the user typed --nsg-ids.
  2. The received value is not shown, making it hard to see what Bash actually parsed.
  3. The user is sent to external documentation instead of getting an inline example.

Context

This is a common stumbling block for Bash users. The safe pattern for embedding variables in JSON array parameters is non-obvious:

# ❌ Bash strips the inner quotes; fails
--nsg-ids "[$NSG_ID]"

# ✅ Backslash-escaped inner quotes; works
--nsg-ids "[\"$NSG_ID\"]"

The existing error message's source code is in src/oci_cli/cli_util.py:

sys.exit('Parameter {!r} must be in JSON format.\nFor help with formatting JSON input ...'.format(parameter_name))

Suggested Fix

Include the received input in the error message so users can see exactly what was parsed:

sys.exit('Parameter {!r} (received as {!r}) must be valid JSON.\nExample: --nsg-ids \'["ocid1.networksecuritygroup..."]\'\nFor more help see: https://docs.cloud.oracle.com/ias/Content/API/SDKDocs/cliusing.htm#ManagingCLIInputandOutput'.format(parameter_name, user_input))

Also consider mapping the internal parameter name back to the CLI flag name (e.g., nsg_ids--nsg-ids) for user-facing output.

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