Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(enterprise/audit): improve error message for missing action
  • Loading branch information
mafredri committed Jul 6, 2023
commit d04af93ff98485f804575c282d3d987209938c5f
10 changes: 9 additions & 1 deletion enterprise/audit/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package audit

import (
"fmt"
"os"
"reflect"
"runtime"

"github.com/coder/coder/coderd/database"
"github.com/coder/coder/codersdk"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}