From d04af93ff98485f804575c282d3d987209938c5f Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Thu, 6 Jul 2023 11:06:36 +0000 Subject: [PATCH 1/2] fix(enterprise/audit): improve error message for missing action --- enterprise/audit/table.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/enterprise/audit/table.go b/enterprise/audit/table.go index 139c240c9f8e1..6e13393c426e4 100644 --- a/enterprise/audit/table.go +++ b/enterprise/audit/table.go @@ -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,8 @@ 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()) + os.Exit(1) } delete(fcpy, jsonTag) } @@ -252,3 +255,8 @@ func entry(v any, f map[string]Action) (string, map[string]Action) { func (t Action) String() string { return string(t) } + +func self() string { + _, file, _, _ := runtime.Caller(1) + return file +} From 43f8373d19b912cba2e1e1b542f7dd6635e9db90 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Thu, 6 Jul 2023 12:32:00 +0000 Subject: [PATCH 2/2] lint --- enterprise/audit/table.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/enterprise/audit/table.go b/enterprise/audit/table.go index 6e13393c426e4..fd7d03827829a 100644 --- a/enterprise/audit/table.go +++ b/enterprise/audit/table.go @@ -238,6 +238,7 @@ func entry(v any, f map[string]Action) (string, map[string]Action) { } if _, ok := fcpy[jsonTag]; !ok { _, _ = 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) @@ -257,6 +258,7 @@ func (t Action) String() string { } func self() string { + //nolint:dogsled _, file, _, _ := runtime.Caller(1) return file }