components
components copied to clipboard
Error states in serverless command are confusing when in components projects
Acknowledging: I've searched this isn't creating a duplicate and it is, I believe, about the core tool (the cli package)
For a new user, the error states in the app are confusing
Right now, a user coming to the Serverless ecosystem is pushed by the website to use components.
However, when interfacing with a components project, doing so some commands that documentation tells the user to try will yield confusing errors.
For example, creating and deploying a new instance of the full-stack
project template and then running serverless info
at the root directory will fail with this error:
"service" property is missing in serverless.yml
This is, however, misleading because the root serverless.yml declaration shouldn't have a "service" property in it. The error is, in fact, that you are running a command in a context that doesn't make sense (that being the container around several components). Thus, the error is obfuscating the actual issue and there isn't sufficient documentation to clarify this.
The same issue crops up for the package
, config
, and logs
commands as well, I'm sure, for many others I didn't test.
Proposed solution
Ideally, the serverless
binary would differentiate between whether it was being run in a the root folder containing several components, or in the folder of a single service/component. Indeed, I assume it is already able to do this for the purposes of adjusting the behavior of the deploy
command.
Using this awareness, the error messages for the various commands in serverless
should be updated to reflect whether the binary thinks that the user is running a command that doesn't make sense given the current context (such as running logs
in the root folder).
In such cases, an error message such as "logs is not supported at the root of a components project" would be much more informative for novice (and even experienced) developers, as it informs them that PEBCAK rather than that there is an error in the configuration for their project.
Great suggestions @zackdotcomputer. We're working on cleaning all of this up now, and we'll keep this in mind.
I get a different error:
fullstack-app sls info
Serverless Error ---------------------------------------
This command can only be run in a Serverless service directory. Make sure to reference a valid config file in the current working directory if you're using a custom config file
The reason this is happening is that we only make a deep search for component instances in child directories in the case of deploy
and remove
commands. That's because this operation is expensive and we did not want to make the framework slower for everyone due to components checks cc @medikoo
@zackdotcomputer I'm guessing you're getting this error because you have a serverless.yml
file in the root of the full stack app? How did that happen though? did you run sls init fullstack-app
? There shouldn't be a yaml file in that case.
@eahefnawy I did the following:
- Go to the "new serverless app" page at
https://app.serverless.com/<USERNAME>/apps/new
- Click "fullstack" card
- Name the app
- Run the
serverless init <TOKEN>
command in my terminal. I've posted the output ofserverless -v
at the end of this comment. -
cd my-serverless-app && ls
shows that the template as created by the server includes aserverless.yml
in the root folder.
If you run serverless info
in that root directory exactly as-is after running init
, then you get the error I reported. Have confirmed that if you rm serverless.yml
from that directory, you get the better error you listed.
Contents of spurious serverless.yml
:
name: my-fullstack-app
app: my-fullstack-app
org: zackdotcomputer
stage: dev
Output of serverless -v
Framework Core: 2.1.1
Plugin: 4.0.4
SDK: 2.3.2
Components: 3.1.3