# 建议：当 app.yaml 存在语法错误时，添加一条有帮助的错误提示

**URL:** <https://meta.discourse.org/t/suggestion-add-a-helpful-error-message-when-app-yaml-has-syntax-errors/111738>\
**Category:** Feature\
**Created:** [2019年三月15日 19:47 UTC](https://meta.discourse.org/t/suggestion-add-a-helpful-error-message-when-app-yaml-has-syntax-errors/111738 "2019-03-15T19:47:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grimz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grimz/32/134170_2.png) [@Grimz](https://meta.discourse.org/u/Grimz)\
**Post date:** [2019年三月15日 19:47 UTC](https://meta.discourse.org/t/suggestion-add-a-helpful-error-message-when-app-yaml-has-syntax-errors/111738/1 "2019-03-15T19:47:45Z")

</div>

When making changes to app.yaml (to add a plugin for instance), it is easy to include extra space, forget a dash, etc. An incorrectly formatted YAML file causes `launcher rebuild app` to fail with the following error:

```plaintext
/merge_command.rb:45:in `merge': no implicit conversion of String into Hash

```

The error code and description in no way imply that there is an issue with parsing app.yaml, nor does it indicate what the problem is with the file. Googling the above error does contain a couple of support links that suggest the issue, but it is far from clear.

Could an error message be added that, at a minimum, indicated that the build tool failed to parse _app.yaml_, or even better, indicate what the syntax or parsing error was (e.g. _“expected indentation on line 17 but found \<tab\>”_, orsimilar)

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2019年三月15日 20:30 UTC](https://meta.discourse.org/t/suggestion-add-a-helpful-error-message-when-app-yaml-has-syntax-errors/111738/2 "2019-03-15T20:30:45Z")

</div>

This is really more of a limitation of the YAML file format than anything else.

About all you can do is pass it to a YAML validator beforehand, but there are _lots_ of ways to mess up a YAML file that keep it _technically valid_ but not working for the settings we’re looking for.

Anything else to add here @sam?

---

<div class="post-metadata">

**Author:** ![csmu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/csmu/32/124581_2.png) [@csmu](https://meta.discourse.org/u/csmu)\
**Post date:** [2019年三月15日 21:16 UTC](https://meta.discourse.org/t/suggestion-add-a-helpful-error-message-when-app-yaml-has-syntax-errors/111738/3 "2019-03-15T21:16:35Z")

</div>

> [@codinghorror](#):
>
> working for the settings we’re looking for

Would it be possible to store the settings in say, app.json and let launcher create a YAML file out of that?

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2019年三月15日 21:47 UTC](https://meta.discourse.org/t/suggestion-add-a-helpful-error-message-when-app-yaml-has-syntax-errors/111738/4 "2019-03-15T21:47:23Z")

</div>

> [@Grimz](#):
>
> Could an error message be added that, at a minimum, indicated that the build tool failed to parse _app.yaml_ , or even better, indicate what the syntax or parsing error was (e.g. _“expected indentation on line 17 but found \<tab\>”_ , orsimilar)

We could try to validate the YAML using the `yamllint` package.

For example, if I try to add a plugin using tabs instead of spaces in the app.yml:

```plaintext
➜ yamllint -d "{extends: relaxed, rules: {line-length: {max: 9999999}}}" standalone.yml
standalone.yml

  92:1 error syntax error: found character '\t' that cannot start any token

```

Is that error above any better?

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2019年三月16日 05:48 UTC](https://meta.discourse.org/t/suggestion-add-a-helpful-error-message-when-app-yaml-has-syntax-errors/111738/5 "2019-03-16T05:48:25Z")

</div>

I am not against writing a “semantic” validator that ensures we know about all the keys and all the keys have the right kind of values in them, but it would be a fair bit of work.

---

<div class="post-metadata">

**Author:** ![Grimz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grimz/32/134170_2.png) [@Grimz](https://meta.discourse.org/u/Grimz)\
**Post date:** [2019年三月18日 14:01 UTC](https://meta.discourse.org/t/suggestion-add-a-helpful-error-message-when-app-yaml-has-syntax-errors/111738/6 "2019-03-18T14:01:17Z")

</div>

> [@Falco](#):
>
> ```plaintext
> ➜ yamllint -d "{extends: relaxed, rules: {line-length: {max: 9999999}}}" standalone.yml
> standalone.yml
> 
> 92:1 error syntax error: found character '\t' that cannot start any token
> 
> ```
> 
> Is that error above any better?

Yes, an error of that sort would definitely have told me that the problem was with my _app.yaml_ file. Even an error just stating that there was an issue with that file would be helpful. This wouldn’t require any kind of linting library.
