-
-
Notifications
You must be signed in to change notification settings - Fork 0
Adds error options to AppError class #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -26,6 +26,7 @@ You can send: | |||||
| * value (type: mixed) | ||||||
| * type (String|Array|Object|Number|Boolean|Date|...) | ||||||
| * me (current method, no validation on the value) | ||||||
| * options (ErrorOptions, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix markdown formatting issues. The line has two formatting issues flagged by markdownlint:
Apply this diff to fix the formatting: - * options (ErrorOptions, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error)
+* options (ErrorOptions, see <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error>)📝 Committable suggestion
Suggested change
🧰 Tools🪛 markdownlint-cli2 (0.18.1)29-29: Unordered list indentation (MD007, ul-indent) 29-29: Bare URL used (MD034, no-bare-urls) 🤖 Prompt for AI Agents |
||||||
|
|
||||||
| It validate the values by this schema: | ||||||
| ```javascript | ||||||
|
|
||||||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||
| import { describe, it } from 'node:test' | ||||||||
|
Check warning on line 1 in src/__tests__/app-error.test.js
|
||||||||
| import assert from 'node:assert' | ||||||||
| import { AppError } from '../index.js' | ||||||||
|
|
||||||||
|
|
@@ -27,7 +27,8 @@ | |||||||
| value: null, | ||||||||
| type: null, | ||||||||
| message: 'Example text', | ||||||||
| me: null | ||||||||
| me: null, | ||||||||
| options: null | ||||||||
|
Comment on lines
+30
to
+31
|
||||||||
| me: null, | |
| options: null | |
| me: null |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new behavior (options.cause propagation) isn't asserted. Add expectations to verify that 'error.cause' is set when provided and absent otherwise, e.g., 'assert.equal(error.cause instanceof Error, true)' and 'assert.equal(error.cause.message, 'Root cause')' for this case, and 'assert.equal(error.cause, undefined)' in the null/undefined options cases.
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test does not assert that the cause is propagated, which is the core behavior introduced by this PR. Add an assertion such as assert.equal(error.cause?.message, 'Root cause') and, in the tests where options is omitted/undefined, assert that error.cause is undefined.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,12 @@ import errorSchema from './schemas/error.js' | |||||||
|
|
||||||||
| const validator = new Validator(errorSchema) | ||||||||
|
|
||||||||
| /** | ||||||||
| * Options for the native Error constructor (ES2022). | ||||||||
| * @typedef {object} ErrorOptions | ||||||||
| * @property {unknown} [cause] | ||||||||
| */ | ||||||||
|
|
||||||||
|
Comment on lines
+7
to
+12
|
||||||||
| /** | ||||||||
| * @typedef {object} ErrorValues | ||||||||
| * @property {string} name | ||||||||
|
|
@@ -24,9 +30,11 @@ export default (error = Error) => | |||||||
| * @param {object=} error.type | ||||||||
| * @param {string} error.message | ||||||||
| * @param {object=} error.me | ||||||||
| * @param {ErrorOptions=} error.options | ||||||||
|
||||||||
| * @param {ErrorOptions=} error.options | |
| * @param {ErrorOptions|undefined|null=} error.options |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Avoid loose equality and the temporary variable; use nullish coalescing inline. For example: super(message, options ?? undefined). This keeps the intent (treat null/undefined as absent) while remaining concise and avoiding ==.
| const opts = options == null ? undefined : options | |
| super(message, opts) | |
| super(message, options ?? undefined) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarify that options must be an object (not null) and that when provided with a cause, it will be available on error.cause. Consider adding a short example: new AppError({ message: '...', options: { cause: new Error('reason') } }) -> error.cause.message === 'reason'.