@lowdefy/errors 0.0.0-experimental-20260202125814 → 0.0.0-experimental-20260202133532
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/dist/ConfigError.js +6 -2
- package/dist/ConfigWarning.js +6 -1
- package/dist/LowdefyError.js +5 -1
- package/dist/PluginError.js +15 -4
- package/dist/ServiceError.js +5 -1
- package/dist/build/ConfigMessage.js +10 -10
- package/dist/build/ConfigWarning.js +5 -0
- package/dist/build/resolveConfigLocation.js +6 -8
- package/dist/formatErrorMessage.js +31 -0
- package/package.json +1 -1
package/dist/ConfigError.js
CHANGED
|
@@ -31,7 +31,11 @@
|
|
|
31
31
|
* configKey: block['~k'],
|
|
32
32
|
* location: { source: 'pages/home.yaml:42', link: '/path/to/pages/home.yaml:42' }
|
|
33
33
|
* });
|
|
34
|
-
*/
|
|
34
|
+
*/ import formatErrorMessage from './formatErrorMessage.js';
|
|
35
|
+
let ConfigError = class ConfigError extends Error {
|
|
36
|
+
print() {
|
|
37
|
+
return formatErrorMessage(this);
|
|
38
|
+
}
|
|
35
39
|
/**
|
|
36
40
|
* Serializes the error for transport (e.g., client to server).
|
|
37
41
|
* @returns {Object} Serialized error data with type marker
|
|
@@ -68,7 +72,7 @@
|
|
|
68
72
|
const configKey = isString ? null : messageOrParams.configKey ?? error?.configKey;
|
|
69
73
|
const location = isString ? null : messageOrParams.location;
|
|
70
74
|
const checkSlug = isString ? undefined : messageOrParams.checkSlug;
|
|
71
|
-
const received = isString ? undefined : messageOrParams.received;
|
|
75
|
+
const received = isString ? undefined : messageOrParams.received !== undefined ? messageOrParams.received : error?.received;
|
|
72
76
|
const operatorLocation = isString ? null : messageOrParams.operatorLocation;
|
|
73
77
|
// Message without prefix - logger uses error.name for display
|
|
74
78
|
super(message);
|
package/dist/ConfigWarning.js
CHANGED
|
@@ -23,12 +23,17 @@
|
|
|
23
23
|
* @example
|
|
24
24
|
* const warning = new ConfigWarning({ message: 'Deprecated feature used', source: 'config.yaml:10' });
|
|
25
25
|
* console.warn(warning.message);
|
|
26
|
-
*/
|
|
26
|
+
*/ import formatErrorMessage from './formatErrorMessage.js';
|
|
27
|
+
let ConfigWarning = class ConfigWarning {
|
|
28
|
+
print() {
|
|
29
|
+
return formatErrorMessage(this);
|
|
30
|
+
}
|
|
27
31
|
/**
|
|
28
32
|
* @param {Object} params
|
|
29
33
|
* @param {string} params.message - The warning message
|
|
30
34
|
* @param {string} [params.source] - Source file:line
|
|
31
35
|
*/ constructor({ message, source }){
|
|
36
|
+
this.name = 'Config Warning';
|
|
32
37
|
// Message without prefix - logger uses class name for display
|
|
33
38
|
this.message = message;
|
|
34
39
|
this.source = source ?? null;
|
package/dist/LowdefyError.js
CHANGED
|
@@ -28,7 +28,11 @@
|
|
|
28
28
|
* console.error(err.message);
|
|
29
29
|
* console.error(err.stack);
|
|
30
30
|
* }
|
|
31
|
-
*/
|
|
31
|
+
*/ import formatErrorMessage from './formatErrorMessage.js';
|
|
32
|
+
let LowdefyError = class LowdefyError extends Error {
|
|
33
|
+
print() {
|
|
34
|
+
return formatErrorMessage(this);
|
|
35
|
+
}
|
|
32
36
|
/**
|
|
33
37
|
* Serializes the error for transport (e.g., client to server).
|
|
34
38
|
* @returns {Object} Serialized error data with type marker
|
package/dist/PluginError.js
CHANGED
|
@@ -35,7 +35,11 @@
|
|
|
35
35
|
* });
|
|
36
36
|
* }
|
|
37
37
|
* // error.message = "[Plugin Error] _if requires boolean test. Received: {...} at blocks.0.properties.visible."
|
|
38
|
-
*/
|
|
38
|
+
*/ import formatErrorMessage from './formatErrorMessage.js';
|
|
39
|
+
let PluginError = class PluginError extends Error {
|
|
40
|
+
print() {
|
|
41
|
+
return formatErrorMessage(this);
|
|
42
|
+
}
|
|
39
43
|
/**
|
|
40
44
|
* Serializes the error for transport (e.g., client to server).
|
|
41
45
|
* @returns {Object} Serialized error data with type marker
|
|
@@ -43,6 +47,7 @@
|
|
|
43
47
|
return {
|
|
44
48
|
'~err': 'PluginError',
|
|
45
49
|
message: this.message,
|
|
50
|
+
rawMessage: this.rawMessage,
|
|
46
51
|
pluginType: this.pluginType,
|
|
47
52
|
pluginName: this.pluginName,
|
|
48
53
|
location: this.location,
|
|
@@ -57,14 +62,20 @@
|
|
|
57
62
|
* @param {Object} data - Serialized error data
|
|
58
63
|
* @returns {PluginError}
|
|
59
64
|
*/ static deserialize(data) {
|
|
65
|
+
// Use rawMessage if available, fallback to message
|
|
66
|
+
const messageToUse = data.rawMessage || data.message;
|
|
60
67
|
const error = new PluginError({
|
|
61
|
-
|
|
68
|
+
message: messageToUse,
|
|
62
69
|
pluginType: data.pluginType,
|
|
63
70
|
pluginName: data.pluginName,
|
|
64
71
|
configKey: data.configKey
|
|
65
72
|
});
|
|
66
73
|
// Set location separately to preserve it without re-formatting message
|
|
67
74
|
error.location = data.location;
|
|
75
|
+
// Preserve the formatted message if different from rawMessage
|
|
76
|
+
if (data.message && data.message !== messageToUse) {
|
|
77
|
+
error.message = data.message;
|
|
78
|
+
}
|
|
68
79
|
if (data.stack) {
|
|
69
80
|
error.stack = data.stack;
|
|
70
81
|
}
|
|
@@ -85,7 +96,7 @@
|
|
|
85
96
|
const rawMessage = message ?? error?.message;
|
|
86
97
|
let formattedMessage = rawMessage;
|
|
87
98
|
if (location) {
|
|
88
|
-
formattedMessage
|
|
99
|
+
formattedMessage = rawMessage != null ? `${rawMessage} at ${location}.` : `at ${location}.`;
|
|
89
100
|
}
|
|
90
101
|
super(formattedMessage, {
|
|
91
102
|
cause: error
|
|
@@ -94,7 +105,7 @@
|
|
|
94
105
|
this.pluginType = pluginType;
|
|
95
106
|
this.pluginName = pluginName;
|
|
96
107
|
this.rawMessage = rawMessage; // Original message without location
|
|
97
|
-
this.received = received;
|
|
108
|
+
this.received = received !== undefined ? received : error?.received;
|
|
98
109
|
this.location = location;
|
|
99
110
|
this.configKey = error?.configKey ?? configKey ?? null;
|
|
100
111
|
// Location info (set by server-side resolution)
|
package/dist/ServiceError.js
CHANGED
|
@@ -48,7 +48,8 @@
|
|
|
48
48
|
* throw new PluginError({ error, ... });
|
|
49
49
|
* }
|
|
50
50
|
* // error.message = "[Service Error] MongoDB: Connection refused. The service may be down..."
|
|
51
|
-
*/
|
|
51
|
+
*/ import formatErrorMessage from './formatErrorMessage.js';
|
|
52
|
+
let ServiceError = class ServiceError extends Error {
|
|
52
53
|
/**
|
|
53
54
|
* Checks if an error is a service error (network issues, timeouts, 5xx).
|
|
54
55
|
* @param {Error} error - The error to check
|
|
@@ -95,6 +96,9 @@
|
|
|
95
96
|
}
|
|
96
97
|
return error.message;
|
|
97
98
|
}
|
|
99
|
+
print() {
|
|
100
|
+
return formatErrorMessage(this);
|
|
101
|
+
}
|
|
98
102
|
/**
|
|
99
103
|
* Serializes the error for transport (e.g., client to server).
|
|
100
104
|
* @returns {Object} Serialized error data with type marker
|
|
@@ -25,8 +25,8 @@ import resolveConfigLocation from './resolveConfigLocation.js';
|
|
|
25
25
|
'link-refs': 'Invalid Link action page reference warnings',
|
|
26
26
|
'request-refs': 'Invalid Request action reference warnings',
|
|
27
27
|
'connection-refs': 'Nonexistent connection ID references',
|
|
28
|
-
types: 'All type validation (blocks, operators, actions, requests, connections)',
|
|
29
|
-
schema: 'JSON schema validation errors'
|
|
28
|
+
'types': 'All type validation (blocks, operators, actions, requests, connections)',
|
|
29
|
+
'schema': 'JSON schema validation errors'
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
32
32
|
* Base class for config message utilities.
|
|
@@ -89,14 +89,14 @@ import resolveConfigLocation from './resolveConfigLocation.js';
|
|
|
89
89
|
const refEntry = context?.refMap?.[operatorLocation.ref];
|
|
90
90
|
const filePath = refEntry?.path ?? 'lowdefy.yaml';
|
|
91
91
|
const lineNumber = operatorLocation.line;
|
|
92
|
-
|
|
93
|
-
let link = null;
|
|
92
|
+
let resolvedPath = filePath;
|
|
94
93
|
if (context?.directories?.config) {
|
|
95
|
-
|
|
94
|
+
resolvedPath = path.join(context.directories.config, filePath);
|
|
96
95
|
}
|
|
96
|
+
const source = lineNumber ? `${resolvedPath}:${lineNumber}` : resolvedPath;
|
|
97
97
|
return {
|
|
98
98
|
source,
|
|
99
|
-
link
|
|
99
|
+
link: source
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
@@ -108,14 +108,14 @@ import resolveConfigLocation from './resolveConfigLocation.js';
|
|
|
108
108
|
* @param {string} [params.configDirectory] - Config directory for link
|
|
109
109
|
* @returns {Object} Location object { source, link }
|
|
110
110
|
*/ static resolveRawLocation({ filePath, lineNumber, configDirectory }) {
|
|
111
|
-
|
|
112
|
-
let link = null;
|
|
111
|
+
let resolvedPath = filePath;
|
|
113
112
|
if (configDirectory) {
|
|
114
|
-
|
|
113
|
+
resolvedPath = path.join(configDirectory, filePath);
|
|
115
114
|
}
|
|
115
|
+
const source = lineNumber ? `${resolvedPath}:${lineNumber}` : resolvedPath;
|
|
116
116
|
return {
|
|
117
117
|
source,
|
|
118
|
-
link
|
|
118
|
+
link: source
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
121
|
};
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import ConfigError from './ConfigError.js';
|
|
16
16
|
import ConfigMessage from './ConfigMessage.js';
|
|
17
|
+
import formatErrorMessage from '../formatErrorMessage.js';
|
|
17
18
|
/**
|
|
18
19
|
* Build-time configuration warning class.
|
|
19
20
|
* All formatting happens in the constructor - properties are ready for the logger.
|
|
@@ -31,6 +32,9 @@ import ConfigMessage from './ConfigMessage.js';
|
|
|
31
32
|
* // Throws ConfigError in prod mode when prodError is true
|
|
32
33
|
* new ConfigWarning({ message, configKey, context, prodError: true });
|
|
33
34
|
*/ let ConfigWarning = class ConfigWarning {
|
|
35
|
+
print() {
|
|
36
|
+
return formatErrorMessage(this);
|
|
37
|
+
}
|
|
34
38
|
/**
|
|
35
39
|
* @param {Object} params
|
|
36
40
|
* @param {string} params.message - The warning message
|
|
@@ -57,6 +61,7 @@ import ConfigMessage from './ConfigMessage.js';
|
|
|
57
61
|
});
|
|
58
62
|
}
|
|
59
63
|
// Store all properties for the logger
|
|
64
|
+
this.name = 'Config Warning';
|
|
60
65
|
this.configKey = configKey ?? null;
|
|
61
66
|
this.checkSlug = checkSlug;
|
|
62
67
|
this.received = received;
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* configDirectory: '/Users/dev/myapp'
|
|
32
32
|
* });
|
|
33
33
|
* // Returns: {
|
|
34
|
-
* // source: 'pages/home.yaml:5',
|
|
34
|
+
* // source: '/Users/dev/myapp/pages/home.yaml:5',
|
|
35
35
|
* // config: 'root.pages[0:home].blocks[0:header]',
|
|
36
36
|
* // link: '/Users/dev/myapp/pages/home.yaml:5'
|
|
37
37
|
* // }
|
|
@@ -44,20 +44,18 @@
|
|
|
44
44
|
const lineNumber = keyEntry['~l'];
|
|
45
45
|
const refEntry = refMap?.[refId];
|
|
46
46
|
const filePath = refEntry?.path || 'lowdefy.yaml';
|
|
47
|
-
// source: filepath:line (e.g., "lowdefy.yaml:16")
|
|
48
|
-
const source = lineNumber ? `${filePath}:${lineNumber}` : filePath;
|
|
49
47
|
// config: the config path (e.g., "root.pages[0:home].blocks[0:header]")
|
|
50
48
|
const config = keyEntry.key;
|
|
51
|
-
//
|
|
52
|
-
let
|
|
49
|
+
// Use absolute path when configDirectory is available for clickable terminal links
|
|
50
|
+
let resolvedPath = filePath;
|
|
53
51
|
if (configDirectory) {
|
|
54
|
-
|
|
55
|
-
link = lineNumber ? `${absolutePath}:${lineNumber}` : absolutePath;
|
|
52
|
+
resolvedPath = path.resolve(configDirectory, filePath);
|
|
56
53
|
}
|
|
54
|
+
const source = lineNumber ? `${resolvedPath}:${lineNumber}` : resolvedPath;
|
|
57
55
|
return {
|
|
58
56
|
source,
|
|
59
57
|
config,
|
|
60
|
-
link
|
|
58
|
+
link: source
|
|
61
59
|
};
|
|
62
60
|
}
|
|
63
61
|
export default resolveConfigLocation;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 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
|
+
*/ function formatErrorMessage(error, { includePrefix = true } = {}) {
|
|
16
|
+
if (typeof error === 'string') return error;
|
|
17
|
+
let message = error?.message || error?.rawMessage || error?.cause?.message || 'Unknown error';
|
|
18
|
+
if (error?.received !== undefined) {
|
|
19
|
+
try {
|
|
20
|
+
message = `${message} Received: ${JSON.stringify(error.received)}`;
|
|
21
|
+
} catch {
|
|
22
|
+
message = `${message} Received: [unserializable]`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (includePrefix) {
|
|
26
|
+
const name = error?.name || 'Error';
|
|
27
|
+
return `[${name}] ${message}`;
|
|
28
|
+
}
|
|
29
|
+
return message;
|
|
30
|
+
}
|
|
31
|
+
export default formatErrorMessage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/errors",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-20260202133532",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Lowdefy error classes for consistent error handling across build, server, and client",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|