refactor: switch from multierr to errors.join

This commit is contained in:
Julien Neuhart
2026-03-27 22:14:01 +01:00
parent d3a65a587c
commit ebf0548d19
9 changed files with 60 additions and 58 deletions

View File

@@ -2,6 +2,7 @@ package chromium
import (
"context"
"errors"
"fmt"
"log/slog"
"net/http"
@@ -17,7 +18,6 @@ import (
"github.com/chromedp/cdproto/runtime"
"github.com/chromedp/chromedp"
"github.com/dlclark/regexp2"
"go.uber.org/multierr"
"golang.org/x/sync/errgroup"
"github.com/gotenberg/gotenberg/v8/pkg/gotenberg"
@@ -231,7 +231,7 @@ func listenForEventResponseReceived(
options.invalidResourceHttpStatusCodeMu.Lock()
defer options.invalidResourceHttpStatusCodeMu.Unlock()
*options.invalidResourceHttpStatusCode = multierr.Append(
*options.invalidResourceHttpStatusCode = errors.Join(
*options.invalidResourceHttpStatusCode,
fmt.Errorf("%s - %d: %s", ev.Response.URL, ev.Response.Status, http.StatusText(int(ev.Response.Status))),
)
@@ -334,7 +334,7 @@ func listenForEventLoadingFailed(ctx context.Context, logger *slog.Logger, optio
// We are looking for common errors.
// TODO: sufficient?
errors := []string{
knownErrors := []string{
"net::ERR_CONNECTION_CLOSED",
"net::ERR_CONNECTION_RESET",
"net::ERR_CONNECTION_REFUSED",
@@ -348,8 +348,8 @@ func listenForEventLoadingFailed(ctx context.Context, logger *slog.Logger, optio
"net::ERR_FILE_NOT_FOUND",
"net::ERR_HTTP2_PROTOCOL_ERROR",
}
if !slices.Contains(errors, ev.ErrorText) {
logger.DebugContext(ctx, fmt.Sprintf("skip EventLoadingFailed: '%s' is not part of %+v", ev.ErrorText, errors))
if !slices.Contains(knownErrors, ev.ErrorText) {
logger.DebugContext(ctx, fmt.Sprintf("skip EventLoadingFailed: '%s' is not part of %+v", ev.ErrorText, knownErrors))
return
}
@@ -378,7 +378,7 @@ func listenForEventLoadingFailed(ctx context.Context, logger *slog.Logger, optio
options.resourceLoadingFailedMu.Lock()
defer options.resourceLoadingFailedMu.Unlock()
*options.resourceLoadingFailed = multierr.Append(
*options.resourceLoadingFailed = errors.Join(
*options.resourceLoadingFailed,
fmt.Errorf("resource %s: %s", ev.Type, ev.ErrorText),
)
@@ -397,7 +397,7 @@ func listenForEventExceptionThrown(ctx context.Context, logger *slog.Logger, con
consoleExceptionsMu.Lock()
defer consoleExceptionsMu.Unlock()
*consoleExceptions = multierr.Append(*consoleExceptions, fmt.Errorf("\n%+v", ev.ExceptionDetails))
*consoleExceptions = errors.Join(*consoleExceptions, fmt.Errorf("\n%+v", ev.ExceptionDetails))
}
})
}

View File

@@ -17,7 +17,6 @@ import (
"github.com/gomarkdown/markdown"
"github.com/labstack/echo/v4"
"github.com/microcosm-cc/bluemonday"
"go.uber.org/multierr"
"github.com/gotenberg/gotenberg/v8/pkg/gotenberg"
"github.com/gotenberg/gotenberg/v8/pkg/modules/api"
@@ -150,7 +149,7 @@ func FormDataChromiumOptions(ctx *api.Context) (*api.FormData, Options) {
for i, cookie := range cookies {
if strings.TrimSpace(cookie.Name) == "" || strings.TrimSpace(cookie.Value) == "" || strings.TrimSpace(cookie.Domain) == "" {
err = multierr.Append(err, fmt.Errorf("cookie %d must have its name, value and domain set", i))
err = errors.Join(err, fmt.Errorf("cookie %d must have its name, value and domain set", i))
}
}
@@ -183,7 +182,7 @@ func FormDataChromiumOptions(ctx *api.Context) (*api.FormData, Options) {
if len(parts) == 2 && strings.ToLower(parts[0]) == "scope" && parts[1] != "" {
scope = parts[1]
} else {
err = multierr.Append(err, fmt.Errorf("invalid scope '%s' for header '%s'", scope, k))
err = errors.Join(err, fmt.Errorf("invalid scope '%s' for header '%s'", scope, k))
invalidScopeToken = true
break
}
@@ -200,7 +199,7 @@ func FormDataChromiumOptions(ctx *api.Context) (*api.FormData, Options) {
if len(scope) > 0 {
p, errCompile := regexp2.Compile(scope, regexp2.None)
if errCompile != nil {
err = multierr.Append(err, fmt.Errorf("invalid scope regex pattern for header '%s': %w", k, errCompile))
err = errors.Join(err, fmt.Errorf("invalid scope regex pattern for header '%s': %w", k, errCompile))
continue
}
scopeRegexp = p
@@ -676,7 +675,7 @@ func markdownToHtml(ctx *api.Context, inputPath string, markdownPaths []string)
}
if path == "" {
markdownFilesNotFoundErr = multierr.Append(
markdownFilesNotFoundErr = errors.Join(
markdownFilesNotFoundErr,
fmt.Errorf("'%s'", filename),
)