lint: Enable "errchkjson" and update json.Marshal error handling.

This commit is contained in:
Joachim Bauch 2025-12-04 10:53:36 +01:00
commit c581bc14d5
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
6 changed files with 13 additions and 19 deletions

View file

@ -1,9 +1,13 @@
version: "2"
linters:
enable:
- errchkjson
- misspell
- revive
settings:
errchkjson:
check-error-free-encoding: true
report-no-exported: true
govet:
enable:
- nilness

View file

@ -167,12 +167,7 @@ func (b *BackendServer) Start(r *mux.Router) error {
"nextcloud-spreed-signaling": "Welcome",
"version": b.version,
}
welcomeMessage, err := json.Marshal(welcome)
if err != nil {
// Should never happen.
return err
}
welcomeMessage, _ := json.Marshal(welcome)
b.welcomeMessage = string(welcomeMessage) + "\n"
if b.debug {

View file

@ -75,10 +75,11 @@ func NewCapabilitiesForTestWithCallback(t *testing.T, callback func(*Capabilitie
config := api.StringMap{
"signaling": signaling,
}
spreedCapa, _ := json.Marshal(api.StringMap{
spreedCapa, err := json.Marshal(api.StringMap{
"features": features,
"config": config,
})
require.NoError(err)
emptyArray := []byte("[]")
response := &CapabilitiesResponse{
Version: CapabilitiesVersion{

View file

@ -414,8 +414,7 @@ func processAuthRequest(t *testing.T, w http.ResponseWriter, r *http.Request, re
userdata := map[string]string{
"displayname": "Displayname " + params.UserId,
}
data, err := json.Marshal(userdata)
require.NoError(err)
data, _ := json.Marshal(userdata)
response.Auth.User = data
return response
}
@ -476,8 +475,7 @@ func processRoomRequest(t *testing.T, w http.ResponseWriter, r *http.Request, re
data := map[string]string{
"userid": "userid-from-sessiondata",
}
tmp, err := json.Marshal(data)
require.NoError(err)
tmp, _ := json.Marshal(data)
response.Room.Session = tmp
case "test-room-initial-permissions":
permissions := []Permission{PERMISSION_MAY_PUBLISH_AUDIO}
@ -777,10 +775,11 @@ func registerBackendHandlerUrl(t *testing.T, router *mux.Router, url string) {
signaling[ConfigKeyHelloV2TokenKey] = string(public)
}
}
spreedCapa, _ := json.Marshal(api.StringMap{
spreedCapa, err := json.Marshal(api.StringMap{
"features": features,
"config": config,
})
assert.NoError(t, err)
response := &CapabilitiesResponse{
Version: CapabilitiesVersion{
Major: 20,

View file

@ -289,11 +289,7 @@ func NewProxyServer(ctx context.Context, r *mux.Router, version string, config *
"nextcloud-spreed-signaling-proxy": "Welcome",
"version": version,
}
welcomeMessage, err := json.Marshal(welcome)
if err != nil {
// Should never happen.
return nil, err
}
welcomeMessage, _ := json.Marshal(welcome)
tokenId, _ := config.GetString("app", "token_id")
var tokenKey *rsa.PrivateKey

View file

@ -54,8 +54,7 @@ func newProxyConfigEtcd(t *testing.T, proxy McuProxy) (*embed.Etcd, ProxyConfig)
func SetEtcdProxy(t *testing.T, etcd *embed.Etcd, path string, proxy *TestProxyInformationEtcd) {
t.Helper()
data, err := json.Marshal(proxy)
require.NoError(t, err)
data, _ := json.Marshal(proxy)
SetEtcdValue(etcd, path, data)
}