Keep the whole startup error when it contains "): " (closes #320)
check / check (push) Waiting to run
check / check (push) Waiting to run
A startup error was cut at its last "): " to drop the annotations fx adds, so the blob_size_limit message, which itself contains "(... size spread): ", lost everything but "need at least N bytes". cleanStartupError now uses dig.RootCause, from the library fx is built on, which removes exactly those annotations and returns the error underneath unchanged. The test starts a real fx app on a config whose blob_size_limit is below the minimum. The old cases fed it plain strings that only looked like fx output; such an error is now rightly left whole, so they are replaced. go.uber.org/dig, already required through fx, becomes a direct requirement in go.mod. Model: opus-5-5
This commit is contained in:
+6
-10
@@ -8,12 +8,12 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/adrg/xdg"
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/dig"
|
||||
"go.uber.org/fx"
|
||||
"sneak.berlin/go/vaultik/internal/config"
|
||||
"sneak.berlin/go/vaultik/internal/database"
|
||||
@@ -146,16 +146,12 @@ func (e *startupError) Error() string {
|
||||
// could not build arguments for function "Y" (file:line): failed to build U:
|
||||
// received non-nil error from function "Z" (file:line): <real error>
|
||||
//
|
||||
// Users care about the real error, not the DI plumbing. We strip everything
|
||||
// up through the last "): " (which is always the close-paren of an fx
|
||||
// function-location annotation followed by the wrapped error).
|
||||
// Users care about the real error, not the DI plumbing. dig.RootCause,
|
||||
// from the library fx is built on, unwraps those layers and returns the
|
||||
// real error whole. Cutting the text at "): " instead would also cut a
|
||||
// real error that contains it, such as the blob_size_limit one.
|
||||
func cleanStartupError(err error) error {
|
||||
msg := err.Error()
|
||||
if idx := strings.LastIndex(msg, "): "); idx >= 0 {
|
||||
msg = msg[idx+3:]
|
||||
}
|
||||
|
||||
return &startupError{msg: msg}
|
||||
return &startupError{msg: dig.RootCause(err).Error()}
|
||||
}
|
||||
|
||||
// RunApp starts the fx application, blocks until it is asked to stop, and
|
||||
|
||||
Reference in New Issue
Block a user