Skip to content
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

fail if an error log has occured #41

Merged
merged 4 commits into from
Jan 13, 2023
Merged

fail if an error log has occured #41

merged 4 commits into from
Jan 13, 2023

Conversation

jhsinger-klotho
Copy link
Contributor

• Does any part of it require special attention?
• Does it relate to or fix any issue? closes #297

making compilation fail if an error is logged. Making consistent message at the end of the failure as well

case for logging an error

jordansinger@Jordans-MacBook-Pro ts-ms-lambda % klotho . --app ondemandddb -p aws -c test/klotho.yaml
██╗  ██╗██╗      ██████╗ ████████╗██╗  ██╗ ██████╗
██║ ██╔╝██║     ██╔═══██╗╚══██╔══╝██║  ██║██╔═══██╗
█████╔╝ ██║     ██║   ██║   ██║   ███████║██║   ██║
██╔═██╗ ██║     ██║   ██║   ██║   ██╔══██║██║   ██║
██║  ██╗███████╗╚██████╔╝   ██║   ██║  ██║╚██████╔╝
╚═╝  ╚═╝╚══════╝ ╚═════╝    ╚═╝   ╚═╝  ╚═╝ ╚═════╝

new update is available, please run klotho --update to get the latest version
Adding resource exec_unit:main
This is a test
| @klotho::persist {
|      id = 'users'
| }
| in users.js
| 8| const users = new Map();

This is a test
| @klotho::expose {
|      id = 'app'
|      target = 'public'
| }
| in index.js
| 36| app.listen(3000, async () => {
| 37|     console.log(`App listening at :3000`);
| 38| });

Found 2 route(s) for middleware 'router'                                                                                                                                                                                      unit: main
Adding resource gateway:app
Adding resource persist_kv:users
Adding resource topology:ondemandddb
Adding resource aws_template_data:ondemandddb
Adding resource infra_as_code:Pulumi (AWS)
Klotho compilation failed

case for an error being returned

jordansinger@Jordans-MacBook-Pro ts-ms-lambda % klotho . --app ondemandddb -p aws -c test/klotho.yaml
██╗  ██╗██╗      ██████╗ ████████╗██╗  ██╗ ██████╗
██║ ██╔╝██║     ██╔═══██╗╚══██╔══╝██║  ██║██╔═══██╗
█████╔╝ ██║     ██║   ██║   ██║   ███████║██║   ██║
██╔═██╗ ██║     ██║   ██║   ██║   ██╔══██║██║   ██║
██║  ██╗███████╗╚██████╔╝   ██║   ██║  ██║╚██████╔╝
╚═╝  ╚═╝╚══════╝ ╚═════╝    ╚═╝   ╚═╝  ╚═╝ ╚═════╝

new update is available, please run klotho --update to get the latest version
Adding resource exec_unit:main
Found 2 route(s) for middleware 'router'                                                                                                                                                                                      unit: main
Adding resource gateway:app
[err 0] error in plugin javascript/Express: error in plugin javascript/Express: 2 errors occurred:
	* This is also a test
	* This is also a test
Klotho compilation failed

Standard checks

  • Unit tests: Any special considerations? nope
  • Docs: Do we need to update any docs, internal or public? nope
  • Backwards compatibility: Will this break existing apps? If so, what would be the extra work required to keep them working? im not sure if we even log errors anywhere but if we do and people are deploying anyways, they wouldnt be able to now

@@ -83,11 +84,7 @@ func main() {

err := root.Execute()
if err != nil {
if cfg.internalDebug {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i was confused on why we have this. just reprints errors it looks like so i removed it. If theres a reason to have it ill add it back and have to change my implementation

Copy link
Contributor

Choose a reason for hiding this comment

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

The difference is in the format: %+v vs %v. The + gives a full stack trace, which is only relevant for us developers and not for users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so do we want to have it as a cli flag then? because this could be exposed to the end user right?

analyticsClient.Error("klotho compiling failed")

cmd.SilenceErrors = true
cmd.SilenceUsage = true
return err
return errors.New("Failed run of klotho invocation")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

because we always set SilenceErrors to true it shouldnt matter what we return, just that we return some error

Copy link
Contributor

@gordon-klotho gordon-klotho left a comment

Choose a reason for hiding this comment

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

The main parts look good, just comments on the extra changes included.

@@ -83,11 +84,7 @@ func main() {

err := root.Execute()
if err != nil {
if cfg.internalDebug {
Copy link
Contributor

Choose a reason for hiding this comment

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

The difference is in the format: %+v vs %v. The + gives a full stack trace, which is only relevant for us developers and not for users.

@@ -83,11 +84,7 @@ func main() {

err := root.Execute()
if err != nil {
if cfg.internalDebug {
zap.S().Errorf("%+v", err)
} else if !root.SilenceErrors {
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this regress the silence errors (which we set on line 270 so it doesn't double-print)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, we still set that to make sure that we dont double print anything

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah we actually will want this so that the non plugin errors surface, going to add it back

if err != nil {
errHandler.PrintErr(err)
} else {
err = errors.New("Failed run of klotho invocation")
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this should go similar to the hadWarnings check (line 94)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that results in a double print as well though since we already log it. i think if we are treating error log lines and errors the same, having them go through the same flow is fine, it then treats zap errors as actual errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we would also still print the output then if we did it that way which i thought this task is trying to prevent

Copy link
Contributor

Choose a reason for hiding this comment

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

True, we do want to prevent writing the output. I guess this error wouldn't get printed since we don't explicitly print it (like we do for err != nil) and also set SilenceErrors. 👍

@github-actions
Copy link

Package Line Rate Health
github.com/klothoplatform/klotho/pkg/analytics 2%
github.com/klothoplatform/klotho/pkg/annotation 24%
github.com/klothoplatform/klotho/pkg/core 20%
github.com/klothoplatform/klotho/pkg/env_var 82%
github.com/klothoplatform/klotho/pkg/exec_unit 45%
github.com/klothoplatform/klotho/pkg/infra/kubernetes 58%
github.com/klothoplatform/klotho/pkg/infra/kubernetes/helm 52%
github.com/klothoplatform/klotho/pkg/input 63%
github.com/klothoplatform/klotho/pkg/lang 37%
github.com/klothoplatform/klotho/pkg/lang/dockerfile 0%
github.com/klothoplatform/klotho/pkg/lang/golang 9%
github.com/klothoplatform/klotho/pkg/lang/javascript 47%
github.com/klothoplatform/klotho/pkg/lang/python 60%
github.com/klothoplatform/klotho/pkg/lang/yaml 0%
github.com/klothoplatform/klotho/pkg/logging 7%
github.com/klothoplatform/klotho/pkg/multierr 95%
github.com/klothoplatform/klotho/pkg/provider/aws 60%
github.com/klothoplatform/klotho/pkg/runtime 75%
github.com/klothoplatform/klotho/pkg/static_unit 32%
github.com/klothoplatform/klotho/pkg/validation 73%
Summary 42% (3592 / 8586)

if err != nil {
errHandler.PrintErr(err)
} else {
err = errors.New("Failed run of klotho invocation")
Copy link
Contributor

Choose a reason for hiding this comment

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

True, we do want to prevent writing the output. I guess this error wouldn't get printed since we don't explicitly print it (like we do for err != nil) and also set SilenceErrors. 👍

@jhsinger-klotho jhsinger-klotho merged commit a7a7511 into main Jan 13, 2023
@jhsinger-klotho jhsinger-klotho deleted the fail_on_error_log branch January 13, 2023 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants