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

Emit Friendly Message When Component Docs Not Found #1032

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ var docsCmd = &cobra.Command{
// Construct the full path to the Terraform component by combining the Atmos base path, Terraform base path, and component name
componentPath := filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, info.Component)
componentPathExists, err := u.IsDirectory(componentPath)
if err != nil {
u.LogErrorAndExit(err)
}
if !componentPathExists {
if err != nil || !componentPathExists {
u.LogErrorAndExit(fmt.Errorf("Component '%s' not found in path: '%s'", info.Component, componentPath))
}

Expand All @@ -83,7 +80,7 @@ var docsCmd = &cobra.Command{

readmeContent, err := os.ReadFile(readmePath)
if err != nil {
u.LogErrorAndExit(err)
u.LogErrorAndExit(fmt.Errorf("Loading README file for component: %s", info.Component))
Copy link
Member

Choose a reason for hiding this comment

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

do we want to show the actual err here?

Copy link
Member

@osterman osterman Feb 6, 2025

Choose a reason for hiding this comment

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

@aknysh is correct, this doesn't achieve the desired outcome. We handle errors today, but it's not friendly.

Here's what we want:

  • If the component folder is not found, say "Component not found"
  • If the component lacks a README.md, say "Documentation is missing for the component asd. Consider adding a README.md to provide more context and details."

Copy link
Member

Choose a reason for hiding this comment

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

Let’s use l.Debug to emit the actual error, and print a friendly one here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That would be useful

Copy link
Member

@osterman osterman Feb 12, 2025

Choose a reason for hiding this comment

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

Also, use l.Fatal instead of u.LogErrorAndExit (deprecated after moving to new logger)

}

r, err := glamour.NewTermRenderer(
Expand All @@ -98,7 +95,7 @@ var docsCmd = &cobra.Command{

componentDocs, err := r.Render(string(readmeContent))
if err != nil {
u.LogErrorAndExit(err)
u.LogErrorAndExit(fmt.Errorf("failed to render markdown: %w", err))
}

pager := atmosConfig.Settings.Terminal.Pager
Expand Down Expand Up @@ -132,7 +129,7 @@ var docsCmd = &cobra.Command{
}

if err != nil {
u.LogErrorAndExit(err)
u.LogErrorAndExit(fmt.Errorf("failed to open default browser: %w", err))
}
}

Expand Down