-
Notifications
You must be signed in to change notification settings - Fork 57
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
Improve bundle validate
output
#1532
Conversation
44a64a2
to
d63d350
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thanks.
Please move the render
package under the top level bundle
package.
Does the output change at all for existing warnings?
@pietern I've manually checked if there is a diff for warnings. There were a couple of extra new lines, and I've added tests for these cases. I also added tests in case the bundle is nil so we don't crash. I also moved the package as you suggested. Please take a look again. |
bundle/render/render_text_output.go
Outdated
// RenderTextOutput renders the diagnostics in a human-readable format. | ||
// | ||
// It prints errors and returns root.AlreadyPrintedErr if there are any errors. | ||
// If there are unexpected errors during rendering, it returns an error different from root.AlreadyPrintedErr. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error isn't returned. Stale comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right. Initially I implemented as described, but then realized it's cleaner not to have this behaviour, and return nil instead.
{{- if .Location.File }} | ||
{{ "in " }}{{ .Location.String | cyan }} | ||
{{- end }} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No detail for warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add it for consistency, but it wasn't there before, and there is no use case for it right now. We simply put the whole body into "summary". I will add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added detail + unit test for it
cmd/bundle/validate.go
Outdated
if err := diags.Error(); err != nil { | ||
return diags.Error() | ||
} else { | ||
panic("failed to load bundle") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please return fmt.Errorf
with some description. Always better (and friendlier) than a panic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why I added panic is because it should never happen. If this happens, invariant is violated, and we have a bug in our code, so we should crash immediately. I can change it to fmt.Errorf
if you think it's more appropriate.
cmd/root/root.go
Outdated
@@ -97,7 +97,7 @@ func Execute(cmd *cobra.Command) { | |||
|
|||
// Run the command | |||
cmd, err := cmd.ExecuteContextC(ctx) | |||
if err != nil { | |||
if err != nil && err != ErrAlreadyPrinted { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use errors.Is
so that it also works if (for whatever reason) the error is wrapped.
2f63090
to
6282a4e
Compare
Bundles: As of this release you can interact with bundles when running the CLI on DBR (e.g. via the Web Terminal). * Fix non-default project names not working in dbt-sql template ([#1500](#1500)). * Improve `bundle validate` output ([#1532](#1532)). * Fixed resolving variable references inside slice variable ([#1550](#1550)). * Fixed bundle not loading when empty variable is defined ([#1552](#1552)). * Use `vfs.Path` for filesystem interaction ([#1554](#1554)). * Replace `vfs.Path` with extension-aware filer when running on DBR ([#1556](#1556)). Internal: * merge.Override: Fix handling of dyn.NilValue ([#1530](#1530)). * Compare `.Kind()` instead of direct equality checks on a `dyn.Value` ([#1520](#1520)). * PythonMutator: register product in user agent extra ([#1533](#1533)). * Ignore `dyn.NilValue` when traversing value from `dyn.Map` ([#1547](#1547)). * Add extra tests for the sync block ([#1548](#1548)). * PythonMutator: add diagnostics ([#1531](#1531)). * PythonMutator: support omitempty in PyDABs ([#1513](#1513)). * PythonMutator: allow insert 'resources' and 'resources.jobs' ([#1555](#1555)).
Bundles: As of this release you can interact with bundles when running the CLI on DBR (e.g. via the Web Terminal). * Fix non-default project names not working in dbt-sql template ([#1500](#1500)). * Improve `bundle validate` output ([#1532](#1532)). * Fixed resolving variable references inside slice variable ([#1550](#1550)). * Fixed bundle not loading when empty variable is defined ([#1552](#1552)). * Use `vfs.Path` for filesystem interaction ([#1554](#1554)). * Replace `vfs.Path` with extension-aware filer when running on DBR ([#1556](#1556)). Internal: * merge.Override: Fix handling of dyn.NilValue ([#1530](#1530)). * Compare `.Kind()` instead of direct equality checks on a `dyn.Value` ([#1520](#1520)). * PythonMutator: register product in user agent extra ([#1533](#1533)). * Ignore `dyn.NilValue` when traversing value from `dyn.Map` ([#1547](#1547)). * Add extra tests for the sync block ([#1548](#1548)). * PythonMutator: add diagnostics ([#1531](#1531)). * PythonMutator: support omitempty in PyDABs ([#1513](#1513)). * PythonMutator: allow insert 'resources' and 'resources.jobs' ([#1555](#1555)).
## Changes This snuck into #1532 right before merging. The result is that error output is no longer logged. This includes actual execution errors as well as help output if arguments or flags are incorrectly specified. We don't have test coverage for the `root.Execute` function. This is to be fixed later. ## Tests Manually confirmed we observe error output again.
Changes
This combination of changes allows pretty-printing errors happening during the "load" and "init" phases, including their locations.
Move to render code into a separate module dedicated to rendering
diag.Diagnostics
in a human-readable format. This will be used for thebundle deploy
command.Preserve the "bundle" value if an error occurs in mutators. Rewrite the go templates to handle the case when the bundle isn't yet loaded if an error occurs during loading, that is possible now.
Improve rendering for errors and warnings:
Add
root.ErrAlreadyPrinted
indicating that the error was already printed, and the CLI entry point shouldn't print it again.Tests
Add tests for output, that are especially handy to detect extra newlines