pangeacyber / pangea-go

Official Pangea Golang Monorepo
https://pangea.cloud
MIT License
9 stars 2 forks source link

redact: error marshalling when debug is true #72

Closed craigpastro closed 1 year ago

craigpastro commented 1 year ago

In the redact service if I make a request with debug=true it returns a score for a word which seems to be a float, which the SDK will try to marshall as an int and the request will fail.

Here is a reproducible code sample:

package main

import (
    "context"
    "fmt"
    "os"

    "github.com/pangeacyber/pangea-go/pangea-sdk/pangea"
    "github.com/pangeacyber/pangea-go/pangea-sdk/service/redact"
)

func main() {
    token := os.Getenv("PANGEA_TOKEN")
    domain := os.Getenv("PANGEA_DOMAIN")
    if token == "" || domain == "" {
        panic("no token or domain")
    }

    cfg := &pangea.Config{
        Token:    token,
        Domain:   os.Getenv("PANGEA_DOMAIN"),
        Insecure: false,
    }

    client := redact.New(cfg)
    resp, err := client.Redact(context.Background(), &redact.TextInput{
        Text:  pangea.String("poop face shit damn 123456 123-4543 134-121-1234"),
        Debug: pangea.Bool(true),
    })
    if err != nil {
        panic(err)
    }

    fmt.Println(*resp.Result.RedactedText)
    for _, rr := range resp.Result.Report.RecognizerResults {
        fmt.Println(*rr.Text, *rr.Score)
    }
}

This code will error with

panic: pangea: POST https://redact.aws.us.pangea.cloud/v1/redact: request_id: prq_rijzlyblwiqsrtpwcc43gw4o5kj2uux5, request_time: 2023-04-26T22:42:30.031426Z, response_time: 2023-04-26T22:42:30.090950Z, status: Success, summary: Success. Redacted 1 item(s) from text: Error: json: cannot unmarshal number 1.0 into Go struct field RecognizerResult.report.recognizer_results.score of type int.

goroutine 1 [running]:
main.main()
        /Users/craig/zandbox/pangea/main.go:32 +0x2bc
exit status 2

Another point: Note that it is actually quite a bit of work to view the RecognizerResults. Is there a way to make this easier by perhaps removing the pointers to primitives for fields which must be there?

pangea-andrest commented 1 year ago

Thanks Craig for feedback and collaboration. Yes, we are planning to remove unneeded pointers like this ones you mention above in SDK v2. I'll take note to avoid forget it.