Last active
August 11, 2022 16:01
-
-
Save nguyenvanduocit/e315f9c7d6c9d0373c46afa3bc2a6bd7 to your computer and use it in GitHub Desktop.
generic error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"errorMessage": "runtime error: invalid memory address or nil pointer dereference", | |
"errorType": "errorString", | |
"stackTrace": [ | |
{ | |
"path": "github.com/aws/[email protected]/lambda/errors.go", | |
"line": 39, | |
"label": "lambdaPanicResponse" | |
}, | |
{ | |
"path": "github.com/aws/[email protected]/lambda/invoke_loop.go", | |
"line": 102, | |
"label": "callBytesHandlerFunc.func1" | |
}, | |
{ | |
"path": "runtime/panic.go", | |
"line": 838, | |
"label": "gopanic" | |
}, | |
{ | |
"path": "runtime/panic.go", | |
"line": 220, | |
"label": "panicmem" | |
}, | |
{ | |
"path": "runtime/signal_unix.go", | |
"line": 818, | |
"label": "sigpanic" | |
}, | |
{ | |
"path": "github.com/aiocean/[email protected]/pixiv/v1/artwork_api.pb.go", | |
"line": 32, | |
"label": "(*GetArtworkResponse).Reset" | |
}, | |
{ | |
"path": "google.golang.org/[email protected]/proto/reset.go", | |
"line": 18, | |
"label": "Reset" | |
}, | |
{ | |
"path": "google.golang.org/[email protected]/encoding/protojson/decode.go", | |
"line": 65, | |
"label": "UnmarshalOptions.unmarshal" | |
}, | |
{ | |
"path": "google.golang.org/[email protected]/encoding/protojson/decode.go", | |
"line": 58, | |
"label": "UnmarshalOptions.Unmarshal" | |
}, | |
{ | |
"path": "google.golang.org/[email protected]/encoding/protojson/decode.go", | |
"line": 29, | |
"label": "Unmarshal" | |
}, | |
{ | |
"path": "import-wallpaper/lambda.go", | |
"line": 67, | |
"label": "invoke[...]" | |
}, | |
{ | |
"path": "import-wallpaper/lambda.go", | |
"line": 82, | |
"label": "getArtwork" | |
}, | |
{ | |
"path": "import-wallpaper/main.go", | |
"line": 15, | |
"label": "Handler" | |
}, | |
{ | |
"path": "reflect/value.go", | |
"line": 556, | |
"label": "Value.call" | |
}, | |
{ | |
"path": "reflect/value.go", | |
"line": 339, | |
"label": "Value.Call" | |
}, | |
{ | |
"path": "github.com/aws/[email protected]/lambda/handler.go", | |
"line": 233, | |
"label": "reflectHandler.func1" | |
}, | |
{ | |
"path": "github.com/aws/[email protected]/lambda/handler.go", | |
"line": 174, | |
"label": "bytesHandlerFunc.Invoke" | |
}, | |
{ | |
"path": "github.com/aws/[email protected]/lambda/invoke_loop.go", | |
"line": 105, | |
"label": "callBytesHandlerFunc" | |
}, | |
{ | |
"path": "github.com/aws/[email protected]/lambda/invoke_loop.go", | |
"line": 73, | |
"label": "handleInvoke" | |
}, | |
{ | |
"path": "github.com/aws/[email protected]/lambda/invoke_loop.go", | |
"line": 37, | |
"label": "startRuntimeAPILoop" | |
}, | |
{ | |
"path": "github.com/aws/[email protected]/lambda/entry.go", | |
"line": 100, | |
"label": "start" | |
}, | |
{ | |
"path": "github.com/aws/[email protected]/lambda/entry.go", | |
"line": 63, | |
"label": "StartWithOptions" | |
}, | |
{ | |
"path": "github.com/aws/[email protected]/lambda/entry.go", | |
"line": 39, | |
"label": "Start" | |
}, | |
{ | |
"path": "import-wallpaper/main.go", | |
"line": 35, | |
"label": "main" | |
}, | |
{ | |
"path": "runtime/proc.go", | |
"line": 250, | |
"label": "main" | |
}, | |
{ | |
"path": "runtime/asm_arm64.s", | |
"line": 1259, | |
"label": "goexit" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// invoke FuncName with data via lambdaClient | |
func invoke[T proto.Message](ctx context.Context, funcName string, data proto.Message) (T, error) { | |
var response T | |
payload, err := protojson.Marshal(data) | |
if err != nil { | |
return response, errors.Wrap(err, "failed to marshal data") | |
} | |
invokeInput := &lambda.InvokeInput{ | |
FunctionName: &funcName, | |
Payload: payload, | |
} | |
invokeOutput, err := getLambdaClient().InvokeWithContext(ctx, invokeInput) | |
if err != nil { | |
return response, errors.Wrap(err, "failed to invoke function") | |
} | |
if statusCode := aws.Int64Value(invokeOutput.StatusCode); statusCode != 200 && statusCode != 202 { | |
return response, errors.New("invoke status code is " + strconv.FormatInt(statusCode, 10) + ": " + *invokeOutput.FunctionError) | |
} | |
if invokeOutput.FunctionError != nil { | |
var invokeErr _InvokeError | |
if err := json.Unmarshal(invokeOutput.Payload, &invokeErr); err != nil { | |
return response, errors.Wrap(err, "failed to unmarshal invoke error") | |
} | |
return response, errors.New(invokeErr.ErrorMessage) | |
} | |
if err := protojson.Unmarshal(invokeOutput.Payload, response); err != nil { | |
return response, errors.Wrap(err, "failed to unmarshal response") | |
} | |
return response, nil | |
} | |
func getArtwork(ctx context.Context, artworkId string) (*pixivv1.Artwork, error) { | |
getArtworkFn, ok := os.LookupEnv(getArtworkEnv) | |
if !ok { | |
return nil, errors.New(getArtworkEnv + " is not set") | |
} | |
request := &pixivv1.GetArtworkRequest{ArtworkId: artworkId} | |
responsePayload, err := invoke[*pixivv1.GetArtworkResponse](ctx, getArtworkFn, request) | |
if err != nil { | |
return nil, errors.Wrap(err, "failed to invoke function pixiv-dev-get-artwork") | |
} | |
return responsePayload.Artwork, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment