aws-amplify / aws-amplify/amplify-cli

Suggestion: Add JSON validation for headless input parameters

Open
#4,490 0 comments 0 reactions 0 assignees View on GitHub
feature-request p3 platform
Dominant language
TypeScript
Stars
2.9k
Forks
825
Avg merge
11d 23h
Merged PRs (30d)
2

Description

**Describe the bug**
Calling `amplify init` with malformed JSON parameters for `amplify` input parameter causes CLI to fail with an unhelpful message

**Amplify CLI Version**
4.21.1

**To Reproduce**
Leave a trailing newline in the Amplify app ID in the input parameter JSON string passed to `amplify init`, e.g.
```
#!/bin/bash

set -e

IFS='|'

AMPLIFY="{\
\"projectName\":\"test-project-name\",\
\"envName\":\"dev\",\
\"appId\":\"12345678
\"\
}"

AWSCLOUDFORMATIONCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":true,\
\"profileName\":\"default\"\
}"

PROVIDERS="{\
\"awscloudformation\":$AWSCLOUDFORMATIONCONFIG\
}"

amplify init \
--amplify $AMPLIFY \
--providers $PROVIDERS \
--yes
```

**Expected behavior**

Expected:
Something like:
```
Invalid JSON passed as `AMPLIFY` parameter: unexpected newline at `"appId":"12345678`
```

Actual:
```
Cannot create property 'providers' on string ''{"projectName":"test-project-name","envName":"dev","appId":"12345678
"}''
```

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. Mac/Windows/Ubuntu]: Linux (unknown distro)
- Node Version. You can use `node -v` to check the node version on your system: 12

**Additional context**
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.