fix(enterprise/audit): improve error message for missing action (#8335)

This commit is contained in:
Mathias Fredriksson
2023-07-06 15:43:32 +03:00
committed by GitHub
parent 7fcf319e01
commit 814534d6b7
+11 -1
View File
@@ -2,7 +2,9 @@ package audit
import (
"fmt"
"os"
"reflect"
"runtime"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/codersdk"
@@ -235,7 +237,9 @@ func entry(v any, f map[string]Action) (string, map[string]Action) {
continue
}
if _, ok := fcpy[jsonTag]; !ok {
panic(fmt.Sprintf("audit table entry missing action for field %q in type %q", d.FieldType.Name, name))
_, _ = fmt.Fprintf(os.Stderr, "ERROR: Audit table entry missing action for field %q in type %q\nPlease update the auditable resource types in: %s\n", d.FieldType.Name, name, self())
//nolint:revive
os.Exit(1)
}
delete(fcpy, jsonTag)
}
@@ -252,3 +256,9 @@ func entry(v any, f map[string]Action) (string, map[string]Action) {
func (t Action) String() string {
return string(t)
}
func self() string {
//nolint:dogsled
_, file, _, _ := runtime.Caller(1)
return file
}