aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.83k stars 822 forks source link

Improve the error flow for non-initialized project #2545

Open undefobj opened 5 years ago

undefobj commented 5 years ago

If I do amplify add xxx in a project which hasn't been initialized we currently spit out an ugly trace:

authtest $amplify-dev add auth
Scanning for plugins...
Plugin scan successful
You are not working inside a valid amplify project.
Use 'amplify init' in the root of your app directory to initialize your project with Amplify
Error: You are not working inside a valid amplify project.
Use 'amplify init' in the root of your app directory to initialize your project with Amplify
    at getAmplifyDirPath (/Users/richardthrelkeld/Downloads/adminauth/amplify-cli/packages/amplify-cli/lib/extensions/amplify-helpers/path-manager.js:49:11)
    at getDotConfigDirPath (/Users/richardthrelkeld/Downloads/adminauth/amplify-cli/packages/amplify-cli/lib/extensions/amplify-helpers/path-manager.js:53:37)
    at Object.getProjectConfigFilePath (/Users/richardthrelkeld/Downloads/adminauth/amplify-cli/packages/amplify-cli/lib/extensions/amplify-helpers/path-manager.js:81:37)
    at AmplifyToolkit.getProjectDetails [as _getProjectDetails] (/Users/richardthrelkeld/Downloads/adminauth/amplify-cli/packages/amplify-cli/lib/extensions/amplify-helpers/get-project-details.js:7:45)
    at Object.run (/Users/richardthrelkeld/Downloads/adminauth/amplify-cli/packages/amplify-category-auth/commands/auth/enable.js:15:34)
    at Object.executeAmplifyCommand (/Users/richardthrelkeld/Downloads/adminauth/amplify-cli/packages/amplify-category-auth/index.js:318:23)
    at /Users/richardthrelkeld/Downloads/adminauth/amplify-cli/packages/amplify-cli/lib/execution-manager.js:114:55
    at step (/Users/richardthrelkeld/Downloads/adminauth/amplify-cli/packages/amplify-cli/lib/execution-manager.js:33:23)
    at Object.next (/Users/richardthrelkeld/Downloads/adminauth/amplify-cli/packages/amplify-cli/lib/execution-manager.js:14:53)
    at fulfilled (/Users/richardthrelkeld/Downloads/adminauth/amplify-cli/packages/amplify-cli/lib/execution-manager.js:5:58)
    at <anonymous>

Why don't we either:

UnleashedMind commented 5 years ago

Added to our backlog

josefaidt commented 2 years ago

Update, the current CLI (10.4.1) prints out an error looking for amplify-meta.json which does not exist when the project is not initialized locally.

πŸ›‘ File at path: '/Users/josef/Documents/projects/aws-amplify/reproductions/authtest/amplify/backend/amplify-meta.json' does not exist
josefaidt commented 1 year ago

steps to reproduce

  1. amplify init -y
  2. git init; git clean -fXd
  3. amplify add x
a1268 on ξ‚  main 
➜  amplify add function
πŸ›‘ File at path: '/Users/josef/Documents/projects/aws-amplify/reproductions/a1268/amplify/.config/local-env-info.json' does not exist

Resolution: Please report this issue at https://github.com/aws-amplify/amplify-cli/issues and include the project identifier from: 'amplify diagnose --send-report'
Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/

Session Identifier: 2fe425ff-c8e5-454d-8040-cac3bb9dbb90
βœ– An unexpected error has occurred, opt in to send an error report to AWS Amplify with non-sensitive project configuration files. Confirm  (y/N) Β· 

πŸ›‘ Failed to report error: 

a1268 on ξ‚  main 
➜  amplify add auth
Using service: Cognito, provided by: awscloudformation
πŸ›‘ Current environment cannot be determined.

Resolution: Use 'amplify init' in the root of your app directory to create a new environment.
Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/

Session Identifier: 08d2cec5-7ff2-4bf9-aaae-1398a4f23a40
βœ– An unexpected error has occurred, opt in to send an error report to AWS Amplify with non-sensitive project configuration files. Confirm  (y/N) Β· 

πŸ›‘ Failed to report error: 

a1268 on ξ‚  main 
➜  amplify add api
? Select from one of the below mentioned services: GraphQL
πŸ›‘ There was an error adding the API resource
πŸ›‘ File at path: '/Users/josef/Documents/projects/aws-amplify/reproductions/a1268/amplify/backend/amplify-meta.json' does not exist

a1268 on ξ‚  main 
➜  amplify env add next --yes
πŸ›‘ Your workspace is not configured to modify the backend.

Resolution: If you wish to change this configuration, remove your `amplify` directory and pull the project again.
Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/

Session Identifier: 2f350b12-7525-49bd-a91b-d2afadcaa39c