chore: add template name to error messages (#26259)
This commit is contained in:
parent
382af7a871
commit
f93b15a8c1
9 changed files with 35 additions and 10 deletions
|
|
@ -367,6 +367,11 @@ export default defineComponent({
|
|||
delete data["icon"];
|
||||
}
|
||||
|
||||
// Remove modbus field if current template doesn't have modbus parameter
|
||||
if (!this.modbus) {
|
||||
delete data["modbus"];
|
||||
}
|
||||
|
||||
// Allow parent to transform API data
|
||||
if (this.transformApiData) {
|
||||
data = this.transformApiData(data, this.values);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
reg "github.com/evcc-io/evcc/util/registry"
|
||||
)
|
||||
|
||||
|
|
@ -20,7 +21,7 @@ func NewFromConfig(ctx context.Context, typ string, other map[string]any) (api.C
|
|||
|
||||
v, err := factory(ctx, other)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot create charger type '%s': %w", typ, err)
|
||||
return nil, fmt.Errorf("cannot create charger type '%s': %w", util.TypeWithTemplateName(typ, other), err)
|
||||
}
|
||||
|
||||
return v, nil
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
reg "github.com/evcc-io/evcc/util/registry"
|
||||
)
|
||||
|
||||
|
|
@ -20,7 +21,7 @@ func NewFromConfig(ctx context.Context, typ string, other map[string]any) (api.M
|
|||
|
||||
v, err := factory(ctx, other)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot create meter type '%s': %w", typ, err)
|
||||
return nil, fmt.Errorf("cannot create meter type '%s': %w", util.TypeWithTemplateName(typ, other), err)
|
||||
}
|
||||
|
||||
return v, nil
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
|
|
@ -17,7 +18,7 @@ func NewFromConfig(ctx context.Context, typ string, other map[string]any) (oauth
|
|||
|
||||
v, err := factory(ctx, other)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("cannot create auth type '%s': %w", typ, err)
|
||||
err = fmt.Errorf("cannot create auth type '%s': %w", util.TypeWithTemplateName(typ, other), err)
|
||||
}
|
||||
|
||||
return v, err
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/evcc-io/evcc/util"
|
||||
reg "github.com/evcc-io/evcc/util/registry"
|
||||
)
|
||||
|
||||
|
|
@ -24,7 +25,7 @@ func NewFromConfig(ctx context.Context, typ string, other map[string]any) (Messe
|
|||
|
||||
v, err := factory(ctx, other)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("cannot create messenger type '%s': %w", typ, err)
|
||||
err = fmt.Errorf("cannot create messenger type '%s': %w", util.TypeWithTemplateName(typ, other), err)
|
||||
}
|
||||
|
||||
return v, err
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
reg "github.com/evcc-io/evcc/util/registry"
|
||||
)
|
||||
|
||||
|
|
@ -25,7 +26,7 @@ func NewFromConfig(ctx context.Context, typ string, other map[string]any) (api.T
|
|||
|
||||
v, err := factory(ctx, other)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot create tariff type '%s': %w", typ, err)
|
||||
return nil, fmt.Errorf("cannot create tariff type '%s': %w", util.TypeWithTemplateName(typ, other), err)
|
||||
}
|
||||
|
||||
// check slot length
|
||||
|
|
|
|||
|
|
@ -33,11 +33,9 @@ var _ api.Tariff = (*cachingProxy)(nil)
|
|||
// NewCachedFromConfig creates a proxy that controls tariff instantiation and caching
|
||||
func NewCachedFromConfig(ctx context.Context, typ string, other map[string]any) (api.Tariff, error) {
|
||||
tariffType := typ
|
||||
if typ == "template" {
|
||||
if template, ok := other["template"].(string); ok {
|
||||
if template := util.TemplateName(typ, other); template != "" {
|
||||
tariffType = template
|
||||
}
|
||||
}
|
||||
|
||||
p := &cachingProxy{
|
||||
ctx: ctx,
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ test.describe("fatal config handling", async () => {
|
|||
// verify loadpoint still visible with error
|
||||
await expect(page.getByTestId("fatal-error")).toBeVisible();
|
||||
await expect(page.getByTestId("fatal-error")).toContainText(
|
||||
/meter: .+? cannot create meter .+?: cannot create meter type 'template': cannot create meter type 'shelly'/
|
||||
/meter: .+? cannot create meter .+?: cannot create meter type 'template:shelly-1pm': cannot create meter type 'shelly'/
|
||||
);
|
||||
await expect(page.getByTestId("fatal-error")).toContainText(
|
||||
/loadpoint: .+? missing charge meter instance/
|
||||
|
|
|
|||
17
util/template.go
Normal file
17
util/template.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package util
|
||||
|
||||
func TypeWithTemplateName(typ string, other map[string]any) string {
|
||||
if template := TemplateName(typ, other); template != "" {
|
||||
typ += ":" + template
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
func TemplateName(typ string, other map[string]any) string {
|
||||
if typ == "template" && other != nil {
|
||||
if template, ok := other["template"].(string); ok && template != "" {
|
||||
return template
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue