Skip to content

feature(config): improved error message for invalid angular-cli.json #2565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2016
Merged

feature(config): improved error message for invalid angular-cli.json #2565

merged 1 commit into from
Oct 10, 2016

Conversation

RoopeHakulinen
Copy link
Contributor

@RoopeHakulinen RoopeHakulinen commented Oct 7, 2016

Earlier invalid angular-cli.json yielded only "Error". Now it prints something like:

Parsing angular-cli.json failed. Please make sure your angular-cli.json is valid JSON. Error:
SyntaxError: Unexpected token s in JSON at position 2

Almost the same message is now also used for the other configuration files (schema and other).

This fixes #2526

@filipesilva
Copy link
Contributor

#2536 is about npm issues so I don't think it'd help. It's a fine idea though, to improve these messages.

@@ -80,10 +80,16 @@ export class CliConfig<JsonType> {

try {
content = JSON.parse(configContent);
} catch (err) {
throw 'Parsing angular-cli.json failed. Please make sure your angular-cli.json is valid'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you throw a new InvalidConfigError with the message both here and below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the class currently declared as InvalidConfigError always just prints "Error", no matter what you pass to it. For that reason I fixed it to use the way provided in this SO answer. Now it prints the error correctly. Also applied the same for another existing use of the InvalidConfigError class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, that works for me. There's some CI errors now though, they seem related to compilation:

packages/angular-cli/models/config/config.ts(10,15): error TS7006: Parameter 'message' implicitly has an 'any' type.

Just a matter of adding constructor(message: string) { I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, how silly of me.. Fixed, let's see if it passes this time :)

@filipesilva
Copy link
Contributor

Oh I see, you wanted to say #2526! I'll edit your comment.

@RoopeHakulinen
Copy link
Contributor Author

Yeah, #2526 is the correct one. Sorry for inconvenience.

Earlier invalid angular-cli.json yielded only "Error". Now it prints something like:

Parsing angular-cli.json failed. Please make sure your angular-cli.json is valid JSON. Error:
SyntaxError: Unexpected token s in JSON at position 2

Almost the same message is now also used for the other configuration files (schema and other).
@filipesilva
Copy link
Contributor

Seems so. I'll merge soon.

@filipesilva filipesilva merged commit db73c0c into angular:master Oct 10, 2016
@RoopeHakulinen RoopeHakulinen deleted the patch-1 branch October 10, 2016 20:09
JJayet pushed a commit to JJayet/angular-cli that referenced this pull request Oct 14, 2016
…ngular#2565)

Earlier invalid angular-cli.json yielded only "Error". Now it prints something like:

Parsing angular-cli.json failed. Please make sure your angular-cli.json is valid JSON. Error:
SyntaxError: Unexpected token s in JSON at position 2

Almost the same message is now also used for the other configuration files (schema and other).
Brocco pushed a commit that referenced this pull request Oct 19, 2016
…2565)

Earlier invalid angular-cli.json yielded only "Error". Now it prints something like:

Parsing angular-cli.json failed. Please make sure your angular-cli.json is valid JSON. Error:
SyntaxError: Unexpected token s in JSON at position 2

Almost the same message is now also used for the other configuration files (schema and other).
texel pushed a commit to splice/angular-cli that referenced this pull request Nov 3, 2016
…ngular#2565)

Earlier invalid angular-cli.json yielded only "Error". Now it prints something like:

Parsing angular-cli.json failed. Please make sure your angular-cli.json is valid JSON. Error:
SyntaxError: Unexpected token s in JSON at position 2

Almost the same message is now also used for the other configuration files (schema and other).
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error message when angular-cli.json is invalid
3 participants