Skip to content

fix: FgaError constructor ignores explicit msg due operator precedence #324

Description

@aaguiarz

Summary

FgaError currently computes its message with:

msg || typeof err === "string" ? (err as string) : `FGA Error ...`

Because of JavaScript operator precedence, this is parsed as:

(msg || typeof err === "string") ? (err as string) : ...

So when a truthy msg is provided, msg is ignored and err is used instead.

Impact

Callers that pass a custom message cannot rely on it being honored, which breaks error wrapping semantics.

Expected

If msg is provided, it should be used as the error message. Otherwise, derive message from err.

Proposed Fix

Use explicit grouping/nullish coalescing, for example:

super(msg ?? (typeof err === "string" ? err : ...));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions