forked from aws/aws-lambda-runtime-interface-emulator
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfatalerror.go
More file actions
71 lines (58 loc) · 2.44 KB
/
fatalerror.go
File metadata and controls
71 lines (58 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package fatalerror
import (
"regexp"
"strings"
)
// This package defines constant error types returned to slicer with DONE(failure), and also sandbox errors
// Separate package for namespacing
// ErrorType is returned to slicer inside DONE
type ErrorType string
// TODO: Find another name than "fatalerror"
// TODO: Rename all const so that they always begin with Agent/Runtime/Sandbox/Function
// TODO: Add filtering for extensions as well
const (
// Extension errors
AgentInitError ErrorType = "Extension.InitError" // agent exited after calling /extension/init/error
AgentExitError ErrorType = "Extension.ExitError" // agent exited after calling /extension/exit/error
AgentCrash ErrorType = "Extension.Crash" // agent crashed unexpectedly
AgentLaunchError ErrorType = "Extension.LaunchError" // agent could not be launched
// Runtime errors
RuntimeExit ErrorType = "Runtime.ExitError"
InvalidEntrypoint ErrorType = "Runtime.InvalidEntrypoint"
InvalidWorkingDir ErrorType = "Runtime.InvalidWorkingDir"
InvalidTaskConfig ErrorType = "Runtime.InvalidTaskConfig"
TruncatedResponse ErrorType = "Runtime.TruncatedResponse"
RuntimeInvalidResponseModeHeader ErrorType = "Runtime.InvalidResponseModeHeader"
RuntimeUnknown ErrorType = "Runtime.Unknown"
// Function errors
FunctionOversizedResponse ErrorType = "Function.ResponseSizeTooLarge"
FunctionUnknown ErrorType = "Function.Unknown"
// Sandbox errors
SandboxFailure ErrorType = "Sandbox.Failure"
SandboxTimeout ErrorType = "Sandbox.Timeout"
)
var validRuntimeAndFunctionErrors = map[ErrorType]struct{}{
// Runtime errors
RuntimeExit: {},
InvalidEntrypoint: {},
InvalidWorkingDir: {},
InvalidTaskConfig: {},
TruncatedResponse: {},
RuntimeInvalidResponseModeHeader: {},
RuntimeUnknown: {},
// Function errors
FunctionOversizedResponse: {},
FunctionUnknown: {},
}
func GetValidRuntimeOrFunctionErrorType(errorType string) ErrorType {
match, _ := regexp.MatchString("(Runtime|Function)\\.[A-Z][a-zA-Z]+", errorType)
if match {
return ErrorType(errorType)
}
if strings.HasPrefix(errorType, "Function.") {
return FunctionUnknown
}
return RuntimeUnknown
}