traefik / yaegi

Yaegi is Another Elegant Go Interpreter
https://pkg.go.dev/github.com/traefik/yaegi
Apache License 2.0
6.96k stars 343 forks source link

Panic while importing "github.com/aws/aws-sdk-go/aws" #1343

Open alekitto opened 2 years ago

alekitto commented 2 years ago

The following program sample.go triggers an unexpected result

package main

import (
    "bytes"
    "context"
    "encoding/base64"
    "fmt"
    "io"
    "net/http"
    "net/url"
    "reflect"
    "strconv"

    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/credentials"
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/lambda"
)

// Config the plugin configuration.
type Config struct {
    AccessKey   string `json:"accessKey,omitempty"`
    SecretKey   string `json:"secretKey,omitempty"`
    Region      string `json:"region,omitempty"`
    FunctionArn string `json:"functionArn,omitempty"`
    Endpoint    string `json:"endpoint,omitempty"`
}

// AwsLambdaPlugin plugin main struct.
type AwsLambdaPlugin struct {
    next        http.Handler
    functionArn string
    name        string
    client      *lambda.Lambda
}

func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error) {
    if len(config.FunctionArn) == 0 {
        return nil, fmt.Errorf("function arn cannot be empty")
    }

    sess := session.Must(session.NewSessionWithOptions(session.Options{
        SharedConfigState: session.SharedConfigEnable,
    }))

    var region *string
    if len(config.Region) > 0 {
        region = aws.String(config.Region)
    }

    var endpoint *string
    if len(config.Endpoint) > 0 {
        endpoint = aws.String(config.Endpoint)
    }

    var creds *credentials.Credentials
    if len(config.AccessKey) > 0 && len(config.SecretKey) > 0 {
        creds = credentials.NewStaticCredentials(config.AccessKey, config.SecretKey, "")
    }

    client := lambda.New(sess, &aws.Config{
        Region:      region,
        Endpoint:    endpoint,
        Credentials: creds,
    })

    return &AwsLambdaPlugin{
        functionArn: config.FunctionArn,
        client:      client,
        next:        next,
        name:        name,
    }, nil
}

Expected result

No error

Got

panic: constant 9223372036854775808 overflows int64

goroutine 1 [running]:
github.com/traefik/yaegi/interp.convertConstantValue(0xc0023485a0)
    /home/runner/work/yaegi/yaegi/interp/run.go:3555 +0x5ab
github.com/traefik/yaegi/interp.convertLiteralValue(0xc0023485a0, {0xfc5f70, 0xce7b20})
    /home/runner/work/yaegi/yaegi/interp/run.go:3528 +0xf9
github.com/traefik/yaegi/interp.doComposite(0xc002345d40, 0x1, 0x1)
    /home/runner/work/yaegi/yaegi/interp/run.go:2673 +0x296
github.com/traefik/yaegi/interp.doCompositeLitKeyed(0x4f3309297adbabb3, 0xd0)
    /home/runner/work/yaegi/yaegi/interp/run.go:2727 +0x1e
github.com/traefik/yaegi/interp.compositeLitKeyed(0xc002348900)
    /home/runner/work/yaegi/yaegi/interp/run.go:2730 +0x1e
github.com/traefik/yaegi/interp.setExec.func1(0xc002345d40)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2577 +0x1f6
github.com/traefik/yaegi/interp.setExec.func1(0xc002348360)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002348000)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002345320)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc0023459e0)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002345440)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002345680)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002343b00)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002344240)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002344fc0)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc0023447e0)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002344a20)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002344c60)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc00233b440)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc00233b680)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc00233b8c0)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc00233bb00)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc00233c240)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc00233bc20)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc00233be60)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc00233a000)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc00233a240)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc00233a480)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc00233a6c0)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc00233a900)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc00233afc0)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc00233aa20)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc00233ac60)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc0023386c0)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002338900)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002338b40)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002338d80)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002338fc0)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002339680)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc0023398c0)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002339b00)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc0023390e0)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002339320)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002337440)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002337680)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc0023378c0)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002337b00)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002337d40)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118
github.com/traefik/yaegi/interp.setExec.func1(0xc002338480)
    /home/runner/work/yaegi/yaegi/interp/cfg.go:2566 +0x118

Yaegi Version

v0.11.2

Additional Notes

No response

codingplz commented 1 year ago

When calling an external code repository, we need to extract it as exported symbols(https://github.com/traefik/yaegi/tree/master/extract), and call Use(Symbols) to make it effective. Without this step, u will get ‘panic: constant xxx overflows int64’, this prompt is not very friendly.