@lowdefy/api 6.2.0 → 6.2.2
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.
|
@@ -25,15 +25,19 @@ import normalizeErrorSources from './normalizeErrorSources.js';
|
|
|
25
25
|
// the serializer's reviver replaces any object holding `~e` with its error, so a
|
|
26
26
|
// plain deserialize of the payload drops `devError` and config never sees it.
|
|
27
27
|
//
|
|
28
|
-
// `received` is left out of devError at every node:
|
|
29
|
-
//
|
|
30
|
-
//
|
|
28
|
+
// `received` is left out of devError at every node: it holds evaluated values,
|
|
29
|
+
// resolved _secret values included, and the dev server can be reached over a LAN
|
|
30
|
+
// or tunnel.
|
|
31
|
+
//
|
|
32
|
+
// A failed request's error carries the connection's error only as a summary, so no log writes
|
|
33
|
+
// the inputs a driver's error can hold; the dev tools get the connection's error itself, from
|
|
34
|
+
// the error's non-enumerable `devCause`.
|
|
31
35
|
function projectDevError(err) {
|
|
32
36
|
const props = {
|
|
33
37
|
message: err.message,
|
|
34
38
|
name: err.name,
|
|
35
39
|
stack: err.stack,
|
|
36
|
-
cause: err.cause,
|
|
40
|
+
cause: err.devCause ?? err.cause,
|
|
37
41
|
...err
|
|
38
42
|
};
|
|
39
43
|
delete props.received;
|
|
@@ -47,9 +47,23 @@ const mockTestRequestError = jest.fn((request)=>{
|
|
|
47
47
|
throw new Error(request.request.message);
|
|
48
48
|
});
|
|
49
49
|
const mockTestRequestWait = jest.fn((request)=>wait(request.request.ms));
|
|
50
|
+
// Fails as a MongoDB write fails schema validation: the driver's error carries the document it
|
|
51
|
+
// rejected.
|
|
52
|
+
const mockTestRequestRejectDocument = jest.fn((request)=>{
|
|
53
|
+
const error = new Error('Document failed validation');
|
|
54
|
+
error.name = 'MongoServerError';
|
|
55
|
+
error.code = 121;
|
|
56
|
+
error.errInfo = {
|
|
57
|
+
details: {
|
|
58
|
+
document: request.request.document
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
throw error;
|
|
62
|
+
});
|
|
50
63
|
mockTestRequest.schema = {};
|
|
51
64
|
mockTestRequestError.schema = {};
|
|
52
65
|
mockTestRequestWait.schema = {};
|
|
66
|
+
mockTestRequestRejectDocument.schema = {};
|
|
53
67
|
mockTestRequest.meta = {
|
|
54
68
|
checkRead: false,
|
|
55
69
|
checkWrite: false
|
|
@@ -62,13 +76,18 @@ mockTestRequestWait.meta = {
|
|
|
62
76
|
checkRead: false,
|
|
63
77
|
checkWrite: false
|
|
64
78
|
};
|
|
79
|
+
mockTestRequestRejectDocument.meta = {
|
|
80
|
+
checkRead: false,
|
|
81
|
+
checkWrite: false
|
|
82
|
+
};
|
|
65
83
|
const connections = {
|
|
66
84
|
TestConnection: {
|
|
67
85
|
schema: {},
|
|
68
86
|
requests: {
|
|
69
87
|
TestRequest: mockTestRequest,
|
|
70
88
|
TestRequestError: mockTestRequestError,
|
|
71
|
-
TestRequestWait: mockTestRequestWait
|
|
89
|
+
TestRequestWait: mockTestRequestWait,
|
|
90
|
+
TestRequestRejectDocument: mockTestRequestRejectDocument
|
|
72
91
|
}
|
|
73
92
|
}
|
|
74
93
|
};
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/ import { RequestError, ServiceError } from '@lowdefy/errors';
|
|
16
16
|
import getCurrentEnvironment from '../../context/getCurrentEnvironment.js';
|
|
17
17
|
import invokeEndpoint from '../endpoints/invokeEndpoint.js';
|
|
18
|
+
import summarisedError from './summarisedError.js';
|
|
18
19
|
async function callRequestResolver(context, { connectionProperties, endpointDepth, requestConfig, requestProperties, requestResolver }) {
|
|
19
20
|
const { blockId, endpointId, logger, pageId, payload } = context;
|
|
20
21
|
// stepId for endpoint steps (after build), requestId for page requests
|
|
@@ -62,13 +63,14 @@ async function callRequestResolver(context, { connectionProperties, endpointDept
|
|
|
62
63
|
});
|
|
63
64
|
return response;
|
|
64
65
|
} catch (error) {
|
|
65
|
-
// Add configKey to any error for location tracing
|
|
66
|
-
|
|
66
|
+
// Add configKey to any error for location tracing. A thrown string or null takes no
|
|
67
|
+
// property, and the TypeError assigning one raises would quote the string.
|
|
68
|
+
if (error instanceof Object && !error.configKey) {
|
|
67
69
|
error.configKey = requestConfig['~k'];
|
|
68
70
|
}
|
|
69
71
|
// Lowdefy errors pass through unchanged — re-wrapping every boundary would
|
|
70
72
|
// nest causes and truncate the deepest (most informative) frame.
|
|
71
|
-
if (error
|
|
73
|
+
if (error?.isLowdefyError) {
|
|
72
74
|
logger.debug({
|
|
73
75
|
params: {
|
|
74
76
|
id: stepOrRequestId,
|
|
@@ -78,13 +80,33 @@ async function callRequestResolver(context, { connectionProperties, endpointDept
|
|
|
78
80
|
}, error.message);
|
|
79
81
|
throw error;
|
|
80
82
|
}
|
|
83
|
+
// The error that leaves here is logged whole at error level by the server's error handler
|
|
84
|
+
// and sent to Sentry, so it carries ids and the resolver's error summarised - never the request's
|
|
85
|
+
// evaluated properties (an agent chat's save-thread step holds the whole thread there) or
|
|
86
|
+
// the connection's error itself, which can embed the document it rejected. The dev tools
|
|
87
|
+
// still show that error: it is kept as devCause, which is not enumerable, so no log or error
|
|
88
|
+
// report walks it, and only the dev error payload reads it. stepId, not requestId: on an
|
|
89
|
+
// error requestId is the HTTP request's id (context.rid) everywhere else.
|
|
90
|
+
const cause = summarisedError(error);
|
|
91
|
+
const addFields = (wrapped)=>{
|
|
92
|
+
Object.assign(wrapped, {
|
|
93
|
+
endpointId: requestConfig.endpointId ?? endpointId,
|
|
94
|
+
stepId: stepOrRequestId,
|
|
95
|
+
connectionId: requestConfig.connectionId
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(wrapped, 'devCause', {
|
|
98
|
+
value: error,
|
|
99
|
+
configurable: true
|
|
100
|
+
});
|
|
101
|
+
};
|
|
81
102
|
// Check if this is a service error (network, timeout, 5xx)
|
|
82
103
|
if (ServiceError.isServiceError(error)) {
|
|
83
104
|
const serviceError = new ServiceError(undefined, {
|
|
84
|
-
cause
|
|
105
|
+
cause,
|
|
85
106
|
service: requestConfig.connectionId,
|
|
86
107
|
configKey: requestConfig['~k']
|
|
87
108
|
});
|
|
109
|
+
addFields(serviceError);
|
|
88
110
|
logger.debug({
|
|
89
111
|
params: {
|
|
90
112
|
id: stepOrRequestId,
|
|
@@ -95,13 +117,13 @@ async function callRequestResolver(context, { connectionProperties, endpointDept
|
|
|
95
117
|
throw serviceError;
|
|
96
118
|
}
|
|
97
119
|
// Wrap other errors in RequestError (request/connection logic error)
|
|
98
|
-
const requestError = new RequestError(
|
|
99
|
-
cause
|
|
120
|
+
const requestError = new RequestError(cause.message, {
|
|
121
|
+
cause,
|
|
100
122
|
typeName: requestConfig.type,
|
|
101
|
-
received: requestProperties,
|
|
102
123
|
location: `${requestConfig.connectionId}/${stepOrRequestId}`,
|
|
103
124
|
configKey: requestConfig['~k']
|
|
104
125
|
});
|
|
126
|
+
addFields(requestError);
|
|
105
127
|
logger.debug({
|
|
106
128
|
params: {
|
|
107
129
|
id: stepOrRequestId,
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { errorSummaryForLog, readErrorCodes } from '@lowdefy/errors';
|
|
16
|
+
// Stack frames name code, never data, so they are kept. The stack's opening lines repeat the
|
|
17
|
+
// message, so they are rebuilt from the summary's; they are dropped by count, not by shape,
|
|
18
|
+
// since a message can hold a line that looks like a frame.
|
|
19
|
+
function stackFrames(error) {
|
|
20
|
+
if (typeof error.stack !== 'string') return [];
|
|
21
|
+
const headerLineCount = String(error).split('\n').length;
|
|
22
|
+
return error.stack.split('\n').slice(headerLineCount).filter((line)=>/^\s+at /.test(line));
|
|
23
|
+
}
|
|
24
|
+
// An error from another realm, such as a DOMException in a VM context, fails instanceof Error.
|
|
25
|
+
function isError(value) {
|
|
26
|
+
if (value instanceof Error) return true;
|
|
27
|
+
return typeof value === 'object' && value !== null && typeof value.stack === 'string' && typeof value.message === 'string';
|
|
28
|
+
}
|
|
29
|
+
function fromSummary(summary, original) {
|
|
30
|
+
const message = summary.message ?? `${summary.name} (message withheld from logs).`;
|
|
31
|
+
const error = new Error(message);
|
|
32
|
+
error.name = summary.name;
|
|
33
|
+
error.stack = [
|
|
34
|
+
`${summary.name}: ${message}`,
|
|
35
|
+
...stackFrames(original)
|
|
36
|
+
].join('\n');
|
|
37
|
+
if (summary.code !== undefined) error.code = summary.code;
|
|
38
|
+
if (summary.statusCode !== undefined) error.statusCode = summary.statusCode;
|
|
39
|
+
const cause = original.lastError ?? original.cause;
|
|
40
|
+
if (summary.cause !== undefined && isError(cause)) {
|
|
41
|
+
error.cause = fromSummary(summary.cause, cause);
|
|
42
|
+
}
|
|
43
|
+
return error;
|
|
44
|
+
}
|
|
45
|
+
// A request resolver's error rebuilt from its log summary: the name, code, status code and
|
|
46
|
+
// message cut to 500 characters, with the stack frames, for the error and three causes. A
|
|
47
|
+
// connection's error can carry the request's inputs in its other fields - a MongoDB write
|
|
48
|
+
// error the document it rejected, an HTTP client's error the request body - and every log
|
|
49
|
+
// and error report writes the error it is given, so none of them is kept.
|
|
50
|
+
function summarisedError(error) {
|
|
51
|
+
if (!isError(error)) {
|
|
52
|
+
const { code, statusCode } = readErrorCodes(error);
|
|
53
|
+
return fromSummary({
|
|
54
|
+
name: 'Error',
|
|
55
|
+
message: `Request resolver threw a value of type ${typeof error}, not an error.`,
|
|
56
|
+
code,
|
|
57
|
+
statusCode
|
|
58
|
+
}, {});
|
|
59
|
+
}
|
|
60
|
+
return fromSummary(errorSummaryForLog(error), error);
|
|
61
|
+
}
|
|
62
|
+
export default summarisedError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/api",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"dist/*"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@lowdefy/ajv": "6.2.
|
|
38
|
-
"@lowdefy/build": "6.2.
|
|
39
|
-
"@lowdefy/errors": "6.2.
|
|
40
|
-
"@lowdefy/helpers": "6.2.
|
|
41
|
-
"@lowdefy/node-utils": "6.2.
|
|
42
|
-
"@lowdefy/nunjucks": "6.2.
|
|
43
|
-
"@lowdefy/operators": "6.2.
|
|
44
|
-
"@lowdefy/operators-js": "6.2.
|
|
37
|
+
"@lowdefy/ajv": "6.2.2",
|
|
38
|
+
"@lowdefy/build": "6.2.2",
|
|
39
|
+
"@lowdefy/errors": "6.2.2",
|
|
40
|
+
"@lowdefy/helpers": "6.2.2",
|
|
41
|
+
"@lowdefy/node-utils": "6.2.2",
|
|
42
|
+
"@lowdefy/nunjucks": "6.2.2",
|
|
43
|
+
"@lowdefy/operators": "6.2.2",
|
|
44
|
+
"@lowdefy/operators-js": "6.2.2",
|
|
45
45
|
"@modelcontextprotocol/sdk": "1.29.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|