@lowdefy/errors 0.0.0-experimental-20260202141952 → 0.0.0-experimental-20260202143246

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