Skip to content

Centralize errors formatting#72

Merged
Vladyslav-Kuksiuk merged 5 commits into
masterfrom
centralize-errors-formatting
Jun 23, 2026
Merged

Centralize errors formatting#72
Vladyslav-Kuksiuk merged 5 commits into
masterfrom
centralize-errors-formatting

Conversation

@Vladyslav-Kuksiuk

@Vladyslav-Kuksiuk Vladyslav-Kuksiuk commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

This PR extracts the error formatting to own logging/error.go which removes code duplication.

Additionally changed the logging tests format to match the project Describe-It format.

Resolves this issue.

@Vladyslav-Kuksiuk Vladyslav-Kuksiuk self-assigned this Jun 23, 2026
@Oleg-Melnik

Copy link
Copy Markdown
Contributor

@codex[agent] review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: a679c0faff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Oleg-Melnik Oleg-Melnik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Vladyslav-Kuksiuk LGTM with minor comment to address.

Comment thread logging/error.go
}

// flattenedErrors returns the leaf errors from a joined error.
func flattenedErrors(err error) []error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this function name lowercase, while the function above is uppercase?

@MykytaPimonovTD MykytaPimonovTD Jun 23, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Oleg-Melnik In GoLang, names that start with an uppercase letter are exported, meaning they can be accessed from other packages. Names that start with a lowercase letter are unexported and can be used only within the same package. This convention provides simple visibility control without separate public or private keywords.

It's a very strange decision, but those are the rules of the language.

This is a docs.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

In Go, names starting with an uppercase letter are public and accessible from other packages. Names starting with a lowercase letter are private to their package.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR centralizes user-facing joined-error formatting into a shared helper in logging/error.go, removing duplication between main.go and the panic-logging path. It also refactors logging tests to use the repository’s Ginkgo/Gomega Describe/It style.

Changes:

  • Extracted joined/nested error flattening + bullet-list formatting into logging.FormatError.
  • Rewired CLI error exit logging and panic formatting to use logging.FormatError.
  • Converted logging/logger_test.go to a Ginkgo/Gomega spec suite and added new specs for error formatting.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
main.go Replaces local error-formatting helpers with logging.FormatError for exit logging.
logging/logger.go Simplifies panic message formatting by delegating to FormatError.
logging/logger_test.go Migrates file URL tests to Ginkgo/Gomega suite style.
logging/error.go New shared implementation for formatting single vs joined/nested errors.
logging/error_test.go Adds specs intended to cover single/nested/joined error formatting behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread logging/error_test.go
Comment on lines +21 to +31
import (
"errors"
"fmt"

"embed-code/embed-code-go/logging"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("Error formatting", func() {

@Vladyslav-Kuksiuk Vladyslav-Kuksiuk Jun 23, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That is not true. All eight tests - four from logger_test and four from error_test - run successfully.
image

Comment thread logging/error.go Outdated
builder.WriteString(message)
builder.WriteString(":")
for _, nestedErr := range errs {
builder.WriteString("\n- ")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think it is better to use platform-specific line separator.

I didn't find a method for it in Go (but try do it by yourself, may be I'm just blind).

If not let's create a util function. Smth like:

lineSeparator := "\n"
if runtime.GOOS == "windows" {
	lineSeparator = "\r\n"
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Go conventionally uses LF for formatted output on every platform. The fmt.Fprintln also emits \n.
image

Comment thread logging/error.go Outdated
builder.WriteString(message)
builder.WriteString(":")
for _, nestedErr := range errs {
builder.WriteString("\n- ")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Also I think it will be prettier with tabulation.

builder.WriteString(lineSeparator)
builder.WriteString("\t- ")
builder.WriteString(nestedErr.Error())

Comment thread logging/error_test.go
"\n- first failure" +
"\n- second failure" +
"\n- third failure"),
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Equal("operation failed:\n" +
				"- first failure\n" +
				"- second failure\n" +
				"- third failure"),

@Vladyslav-Kuksiuk Vladyslav-Kuksiuk merged commit 39810fa into master Jun 23, 2026
3 checks passed
@Vladyslav-Kuksiuk Vladyslav-Kuksiuk deleted the centralize-errors-formatting branch June 23, 2026 15:05
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.

Centralize joined-error formatting

4 participants