@platformatic/runtime 3.0.0-alpha.4 → 3.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/errors.js CHANGED
@@ -1,158 +1,124 @@
1
- 'use strict'
1
+ import createError from '@fastify/error'
2
2
 
3
- const createError = require('@fastify/error')
3
+ export const ERROR_PREFIX = 'PLT_RUNTIME'
4
4
 
5
- const ERROR_PREFIX = 'PLT_RUNTIME'
6
-
7
- const AddressInUseError = createError(
5
+ export const AddressInUseError = createError(
8
6
  `${ERROR_PREFIX}_EADDR_IN_USE`,
9
7
  'The current port is in use by another application'
10
8
  )
11
- const RuntimeExitedError = createError(
9
+ export const RuntimeExitedError = createError(
12
10
  `${ERROR_PREFIX}_RUNTIME_EXIT`,
13
11
  'The runtime exited before the operation completed'
14
12
  )
15
- const RuntimeAbortedError = createError(`${ERROR_PREFIX}_RUNTIME_ABORT`, 'The runtime aborted the operation')
13
+ export const RuntimeAbortedError = createError(`${ERROR_PREFIX}_RUNTIME_ABORT`, 'The runtime aborted the operation')
16
14
  // The following two use the same code as we only need to differentiate the label
17
- const ServiceExitedError = createError(
18
- `${ERROR_PREFIX}_SERVICE_EXIT`,
19
- 'The service "%s" exited prematurely with error code %d'
15
+ export const ApplicationExitedError = createError(
16
+ `${ERROR_PREFIX}_APPLICATION_EXIT`,
17
+ 'The application "%s" exited prematurely with error code %d'
20
18
  )
21
- const WorkerExitedError = createError(
22
- `${ERROR_PREFIX}_SERVICE_EXIT`,
23
- 'The worker %s of the service "%s" exited prematurely with error code %d'
19
+ export const WorkerExitedError = createError(
20
+ `${ERROR_PREFIX}_APPLICATION_WORKER_EXIT`,
21
+ 'The worker %s of the application "%s" exited prematurely with error code %d'
24
22
  )
25
- const UnknownRuntimeAPICommandError = createError(
23
+ export const UnknownRuntimeAPICommandError = createError(
26
24
  `${ERROR_PREFIX}_UNKNOWN_RUNTIME_API_COMMAND`,
27
25
  'Unknown Runtime API command "%s"'
28
26
  )
29
- const ServiceNotFoundError = createError(
30
- `${ERROR_PREFIX}_SERVICE_NOT_FOUND`,
31
- 'Service %s not found. Available services are: %s'
27
+ export const ApplicationNotFoundError = createError(
28
+ `${ERROR_PREFIX}_APPLICATION_NOT_FOUND`,
29
+ 'Application %s not found. Available applications are: %s'
32
30
  )
33
- const WorkerNotFoundError = createError(
31
+ export const WorkerNotFoundError = createError(
34
32
  `${ERROR_PREFIX}_WORKER_NOT_FOUND`,
35
- 'Worker %s of service %s not found. Available services are: %s'
33
+ 'Worker %s of application %s not found. Available applications are: %s'
34
+ )
35
+ export const ApplicationNotStartedError = createError(
36
+ `${ERROR_PREFIX}_APPLICATION_NOT_STARTED`,
37
+ "Application with id '%s' is not started"
36
38
  )
37
- const ServiceNotStartedError = createError(`${ERROR_PREFIX}_SERVICE_NOT_STARTED`, "Service with id '%s' is not started")
38
- const ServiceStartTimeoutError = createError(
39
- `${ERROR_PREFIX}_SERVICE_START_TIMEOUT`,
40
- "Service with id '%s' failed to start in %dms."
39
+ export const ApplicationStartTimeoutError = createError(
40
+ `${ERROR_PREFIX}_APPLICATION_START_TIMEOUT`,
41
+ "Application with id '%s' failed to start in %dms."
41
42
  )
42
- const FailedToRetrieveOpenAPISchemaError = createError(
43
+ export const FailedToRetrieveOpenAPISchemaError = createError(
43
44
  `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_OPENAPI_SCHEMA`,
44
- 'Failed to retrieve OpenAPI schema for service with id "%s": %s'
45
+ 'Failed to retrieve OpenAPI schema for application with id "%s": %s'
45
46
  )
46
- const FailedToRetrieveGraphQLSchemaError = createError(
47
+ export const FailedToRetrieveGraphQLSchemaError = createError(
47
48
  `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_GRAPHQL_SCHEMA`,
48
- 'Failed to retrieve GraphQL schema for service with id "%s": %s'
49
+ 'Failed to retrieve GraphQL schema for application with id "%s": %s'
49
50
  )
50
- const FailedToRetrieveMetaError = createError(
51
+ export const FailedToRetrieveMetaError = createError(
51
52
  `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_META`,
52
- 'Failed to retrieve metadata for service with id "%s": %s'
53
+ 'Failed to retrieve metadata for application with id "%s": %s'
53
54
  )
54
- const FailedToRetrieveMetricsError = createError(
55
+ export const FailedToRetrieveMetricsError = createError(
55
56
  `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_METRICS`,
56
- 'Failed to retrieve metrics for service with id "%s": %s'
57
+ 'Failed to retrieve metrics for application with id "%s": %s'
57
58
  )
58
- const FailedToRetrieveHealthError = createError(
59
+ export const FailedToRetrieveHealthError = createError(
59
60
  `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_HEALTH`,
60
- 'Failed to retrieve health for service with id "%s": %s'
61
+ 'Failed to retrieve health for application with id "%s": %s'
61
62
  )
62
- const FailedToPerformCustomHealthCheckError = createError(
63
+ export const FailedToPerformCustomHealthCheckError = createError(
63
64
  `${ERROR_PREFIX}_FAILED_TO_PERFORM_CUSTOM_HEALTH_CHECK`,
64
- 'Failed to perform custom healthcheck for service with id "%s": %s'
65
+ 'Failed to perform custom healthcheck for application with id "%s": %s'
65
66
  )
66
- const FailedToPerformCustomReadinessCheckError = createError(
67
+ export const FailedToPerformCustomReadinessCheckError = createError(
67
68
  `${ERROR_PREFIX}_FAILED_TO_PERFORM_CUSTOM_READINESS_CHECK`,
68
- 'Failed to perform custom readiness check for service with id "%s": %s'
69
+ 'Failed to perform custom readiness check for application with id "%s": %s'
69
70
  )
70
- const ApplicationAlreadyStartedError = createError(
71
+ export const ApplicationAlreadyStartedError = createError(
71
72
  `${ERROR_PREFIX}_APPLICATION_ALREADY_STARTED`,
72
73
  'Application is already started'
73
74
  )
74
- const ApplicationNotStartedError = createError(
75
- `${ERROR_PREFIX}_APPLICATION_NOT_STARTED`,
76
- 'Application has not been started'
77
- )
78
- const ConfigPathMustBeStringError = createError(
75
+ export const RuntimeNotStartedError = createError(`${ERROR_PREFIX}_NOT_STARTED`, 'Application has not been started')
76
+ export const ConfigPathMustBeStringError = createError(
79
77
  `${ERROR_PREFIX}_CONFIG_PATH_MUST_BE_STRING`,
80
78
  'Config path must be a string'
81
79
  )
82
- const NoConfigFileFoundError = createError(
80
+ export const NoConfigFileFoundError = createError(
83
81
  `${ERROR_PREFIX}_NO_CONFIG_FILE_FOUND`,
84
- "No config file found for service '%s'"
82
+ "No config file found for application '%s'"
85
83
  )
86
- const InvalidEntrypointError = createError(
84
+ export const InvalidEntrypointError = createError(
87
85
  `${ERROR_PREFIX}_INVALID_ENTRYPOINT`,
88
86
  "Invalid entrypoint: '%s' does not exist"
89
87
  )
90
- const MissingEntrypointError = createError(`${ERROR_PREFIX}_MISSING_ENTRYPOINT`, 'Missing application entrypoint.')
91
- const InvalidServicesWithWebError = createError(
92
- `${ERROR_PREFIX}_INVALID_SERVICES_WITH_WEB`,
93
- 'The "services" property cannot be used when the "web" property is also defined'
88
+ export const MissingEntrypointError = createError(
89
+ `${ERROR_PREFIX}_MISSING_ENTRYPOINT`,
90
+ 'Missing application entrypoint.'
94
91
  )
95
- const MissingDependencyError = createError(`${ERROR_PREFIX}_MISSING_DEPENDENCY`, 'Missing dependency: "%s"')
96
- const InspectAndInspectBrkError = createError(
92
+ export const MissingDependencyError = createError(`${ERROR_PREFIX}_MISSING_DEPENDENCY`, 'Missing dependency: "%s"')
93
+ export const InspectAndInspectBrkError = createError(
97
94
  `${ERROR_PREFIX}_INSPECT_AND_INSPECT_BRK`,
98
95
  '--inspect and --inspect-brk cannot be used together'
99
96
  )
100
- const InspectorPortError = createError(
97
+ export const InspectorPortError = createError(
101
98
  `${ERROR_PREFIX}_INSPECTOR_PORT`,
102
99
  'Inspector port must be 0 or in range 1024 to 65535'
103
100
  )
104
- const InspectorHostError = createError(`${ERROR_PREFIX}_INSPECTOR_HOST`, 'Inspector host cannot be empty')
105
- const CannotMapSpecifierToAbsolutePathError = createError(
101
+ export const InspectorHostError = createError(`${ERROR_PREFIX}_INSPECTOR_HOST`, 'Inspector host cannot be empty')
102
+ export const CannotMapSpecifierToAbsolutePathError = createError(
106
103
  `${ERROR_PREFIX}_CANNOT_MAP_SPECIFIER_TO_ABSOLUTE_PATH`,
107
104
  'Cannot map "%s" to an absolute path'
108
105
  )
109
- const NodeInspectorFlagsNotSupportedError = createError(
106
+ export const NodeInspectorFlagsNotSupportedError = createError(
110
107
  `${ERROR_PREFIX}_NODE_INSPECTOR_FLAGS_NOT_SUPPORTED`,
111
108
  "The Node.js inspector flags are not supported. Please use 'platformatic start --inspect' instead."
112
109
  )
113
- const FailedToUnlinkManagementApiSocket = createError(
110
+ export const FailedToUnlinkManagementApiSocket = createError(
114
111
  `${ERROR_PREFIX}_FAILED_TO_UNLINK_MANAGEMENT_API_SOCKET`,
115
112
  'Failed to unlink management API socket "%s"'
116
113
  )
117
- const LogFileNotFound = createError(`${ERROR_PREFIX}_LOG_FILE_NOT_FOUND`, 'Log file with index %s not found', 404)
118
- const WorkerIsRequired = createError(`${ERROR_PREFIX}_REQUIRED_WORKER`, 'The worker parameter is required')
119
- const InvalidArgumentError = createError(`${ERROR_PREFIX}_INVALID_ARGUMENT`, 'Invalid argument: "%s"')
120
- const MessagingError = createError(`${ERROR_PREFIX}_MESSAGING_ERROR`, 'Cannot send a message to service "%s": %s')
121
-
122
- module.exports = {
123
- AddressInUseError,
124
- RuntimeExitedError,
125
- RuntimeAbortedError,
126
- ServiceExitedError,
127
- WorkerExitedError,
128
- UnknownRuntimeAPICommandError,
129
- ServiceNotFoundError,
130
- WorkerNotFoundError,
131
- ServiceNotStartedError,
132
- ServiceStartTimeoutError,
133
- FailedToRetrieveOpenAPISchemaError,
134
- FailedToRetrieveGraphQLSchemaError,
135
- FailedToRetrieveMetaError,
136
- FailedToRetrieveMetricsError,
137
- FailedToRetrieveHealthError,
138
- FailedToPerformCustomHealthCheckError,
139
- FailedToPerformCustomReadinessCheckError,
140
- ApplicationAlreadyStartedError,
141
- ApplicationNotStartedError,
142
- ConfigPathMustBeStringError,
143
- NoConfigFileFoundError,
144
- InvalidEntrypointError,
145
- MissingEntrypointError,
146
- InvalidServicesWithWebError,
147
- MissingDependencyError,
148
- InspectAndInspectBrkError,
149
- InspectorPortError,
150
- InspectorHostError,
151
- CannotMapSpecifierToAbsolutePathError,
152
- NodeInspectorFlagsNotSupportedError,
153
- FailedToUnlinkManagementApiSocket,
154
- LogFileNotFound,
155
- WorkerIsRequired,
156
- InvalidArgumentError,
157
- MessagingError
158
- }
114
+ export const LogFileNotFound = createError(
115
+ `${ERROR_PREFIX}_LOG_FILE_NOT_FOUND`,
116
+ 'Log file with index %s not found',
117
+ 404
118
+ )
119
+ export const WorkerIsRequired = createError(`${ERROR_PREFIX}_REQUIRED_WORKER`, 'The worker parameter is required')
120
+ export const InvalidArgumentError = createError(`${ERROR_PREFIX}_INVALID_ARGUMENT`, 'Invalid argument: "%s"')
121
+ export const MessagingError = createError(
122
+ `${ERROR_PREFIX}_MESSAGING_ERROR`,
123
+ 'Cannot send a message to application "%s": %s'
124
+ )