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

Improve bundle validate output #1532

Merged
merged 11 commits into from
Jul 1, 2024

Conversation

kanterov
Copy link
Contributor

@kanterov kanterov commented Jun 26, 2024

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 the bundle 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:

  • don't render empty locations
  • render "details" for errors if they exist

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

@kanterov kanterov marked this pull request as draft June 26, 2024 14:54
Copy link
Contributor

@pietern pietern left a 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?

cmd/bundle/utils/utils.go Show resolved Hide resolved
@kanterov kanterov marked this pull request as ready for review June 27, 2024 13:21
@kanterov
Copy link
Contributor Author

@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.

@kanterov kanterov requested a review from pietern June 27, 2024 13:22
// 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.
Copy link
Contributor

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?

Copy link
Contributor Author

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 }}

Copy link
Contributor

Choose a reason for hiding this comment

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

No detail for warning?

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 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.

Copy link
Contributor Author

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

if err := diags.Error(); err != nil {
return diags.Error()
} else {
panic("failed to load bundle")
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

@pietern pietern enabled auto-merge July 1, 2024 08:56
@pietern pietern added this pull request to the merge queue Jul 1, 2024
Merged via the queue into databricks:main with commit e8b76a7 Jul 1, 2024
5 checks passed
pietern added a commit that referenced this pull request Jul 3, 2024
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)).
@pietern pietern mentioned this pull request Jul 3, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jul 3, 2024
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)).
pietern added a commit that referenced this pull request Jul 3, 2024
@pietern pietern mentioned this pull request Jul 3, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jul 3, 2024
## 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.
pietern added a commit that referenced this pull request Jul 3, 2024
This bugfix release fixes missing error messages in v0.223.0.

CLI:
 * Fix logic error in [#1532](#1532) ([#1564](#1564)).
@pietern pietern mentioned this pull request Jul 3, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jul 3, 2024
This bugfix release fixes missing error messages in v0.223.0.

CLI:
* Fix logic error in
[#1532](#1532)
([#1564](#1564)).
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