Skip to content

Commit

Permalink
feat:simplify error messages on tuple write
Browse files Browse the repository at this point in the history
corrected indentation

feat:simplify error messages on tuple write

resolved linting issues

updated extractErrMssg function

Signed-off-by: shruti2522 <[email protected]>

resolved linting issues

Signed-off-by: shruti2522 <[email protected]>

feat:simplify error messages on tuple write

Signed-off-by: shruti2522 <[email protected]>
  • Loading branch information
shruti2522 committed Apr 24, 2024
1 parent cc62e25 commit 6443309
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions cmd/tuple/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"os"
"strings"

openfga "github.com/openfga/go-sdk"
"github.com/openfga/go-sdk/client"
Expand Down Expand Up @@ -81,6 +82,20 @@ func ImportTuples(
return &result, nil
}

func extractErrMssg(err error) string {
errorMsg := err.Error()
startIndex := strings.Index(errorMsg, "error message:")

if startIndex == -1 {
return errorMsg
}

errorMsg = errorMsg[startIndex:]
errorMsg = strings.TrimSpace(errorMsg)

return errorMsg
}

func processWrites(
writes []client.ClientWriteRequestWriteResponse,
) ([]client.ClientTupleKey, []failedWriteResponse) {
Expand All @@ -93,9 +108,10 @@ func processWrites(
if write.Status == client.SUCCESS {
successfulWrites = append(successfulWrites, write.TupleKey)
} else {
reason := extractErrMssg(write.Error)
failedWrites = append(failedWrites, failedWriteResponse{
TupleKey: write.TupleKey,
Reason: write.Error.Error(),
Reason: reason,
})
}
}
Expand All @@ -121,9 +137,10 @@ func processDeletes(
if delete.Status == client.SUCCESS {
successfulDeletes = append(successfulDeletes, deletedTupleKey)
} else {
reason := extractErrMssg(delete.Error)
failedDeletes = append(failedDeletes, failedWriteResponse{
TupleKey: deletedTupleKey,
Reason: delete.Error.Error(),
Reason: reason,
})
}
}
Expand Down

0 comments on commit 6443309

Please sign in to comment.