Skip to content

Missing Error Handling for JSON Marshaling in clearByField Function #223

Description

@norwayiscoming

The clearByField function is responsible for generating and handling commands related to clearing subscriber sessions based on a particular field, such as session ID or MAC address. While this function correctly checks for a missing argument and returns an error, there is a lack of additional context when handling errors related to JSON marshaling.

When the json.Marshal function is called, it can produce an error if there is an issue encoding the map to JSON. Currently, if this occurs, the error returned is simply wrapped with a generic message: "failed to encode request". For improved debugging and troubleshooting, it would be beneficial to include more detailed context about the function's parameters or the field involved in the marshaling.

For example, instead of just returning fmt.Errorf("failed to encode request: %w", err), consider enhancing the error message with specifics about what was being marshaled. This can help pinpoint the source of the error during development or in production logs:

return fmt.Errorf("failed to encode request for field '%s' with value '%s': %w", field, args[0], err)

By doing this, developers and support engineers will find it easier to debug issues related to JSON encoding failures.


Reported by frontend_lia_4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions