adapt-authoring-errors 0.0.1 → 1.0.0

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/.eslintignore CHANGED
@@ -1 +1 @@
1
- node_modules
1
+ node_modules
package/.eslintrc CHANGED
@@ -1,14 +1,14 @@
1
- {
2
- "env": {
3
- "browser": false,
4
- "node": true,
5
- "commonjs": false,
6
- "es2020": true
7
- },
8
- "extends": [
9
- "standard"
10
- ],
11
- "parserOptions": {
12
- "ecmaVersion": 2020
13
- }
14
- }
1
+ {
2
+ "env": {
3
+ "browser": false,
4
+ "node": true,
5
+ "commonjs": false,
6
+ "es2020": true
7
+ },
8
+ "extends": [
9
+ "standard"
10
+ ],
11
+ "parserOptions": {
12
+ "ecmaVersion": 2020
13
+ }
14
+ }
@@ -1,55 +1,55 @@
1
- name: Bug Report
2
- description: File a bug report
3
- labels: ["bug"]
4
- body:
5
- - type: markdown
6
- attributes:
7
- value: |
8
- Thanks for taking the time to fill out this bug report!
9
- - type: textarea
10
- id: description
11
- attributes:
12
- label: What happened?
13
- description: Please describe the issue
14
- validations:
15
- required: true
16
- - type: textarea
17
- id: expected
18
- attributes:
19
- label: Expected behaviour
20
- description: Tell us what should have happened
21
- - type: textarea
22
- id: repro-steps
23
- attributes:
24
- label: Steps to reproduce
25
- description: Tell us how to reproduce the issue
26
- validations:
27
- required: true
28
- - type: input
29
- id: aat-version
30
- attributes:
31
- label: Authoring tool version
32
- description: What version of the Adapt authoring tool are you running?
33
- validations:
34
- required: true
35
- - type: input
36
- id: fw-version
37
- attributes:
38
- label: Framework version
39
- description: What version of the Adapt framework are you running?
40
- - type: dropdown
41
- id: browsers
42
- attributes:
43
- label: What browsers are you seeing the problem on?
44
- multiple: true
45
- options:
46
- - Firefox
47
- - Chrome
48
- - Safari
49
- - Microsoft Edge
50
- - type: textarea
51
- id: logs
52
- attributes:
53
- label: Relevant log output
54
- description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
55
- render: sh
1
+ name: Bug Report
2
+ description: File a bug report
3
+ labels: ["bug"]
4
+ body:
5
+ - type: markdown
6
+ attributes:
7
+ value: |
8
+ Thanks for taking the time to fill out this bug report!
9
+ - type: textarea
10
+ id: description
11
+ attributes:
12
+ label: What happened?
13
+ description: Please describe the issue
14
+ validations:
15
+ required: true
16
+ - type: textarea
17
+ id: expected
18
+ attributes:
19
+ label: Expected behaviour
20
+ description: Tell us what should have happened
21
+ - type: textarea
22
+ id: repro-steps
23
+ attributes:
24
+ label: Steps to reproduce
25
+ description: Tell us how to reproduce the issue
26
+ validations:
27
+ required: true
28
+ - type: input
29
+ id: aat-version
30
+ attributes:
31
+ label: Authoring tool version
32
+ description: What version of the Adapt authoring tool are you running?
33
+ validations:
34
+ required: true
35
+ - type: input
36
+ id: fw-version
37
+ attributes:
38
+ label: Framework version
39
+ description: What version of the Adapt framework are you running?
40
+ - type: dropdown
41
+ id: browsers
42
+ attributes:
43
+ label: What browsers are you seeing the problem on?
44
+ multiple: true
45
+ options:
46
+ - Firefox
47
+ - Chrome
48
+ - Safari
49
+ - Microsoft Edge
50
+ - type: textarea
51
+ id: logs
52
+ attributes:
53
+ label: Relevant log output
54
+ description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
55
+ render: sh
@@ -1,22 +1,22 @@
1
- name: Feature request
2
- description: Request a new feature
3
- labels: ["enhancement"]
4
- body:
5
- - type: markdown
6
- attributes:
7
- value: |
8
- Thanks for taking the time to request a new feature in the Adapt authoring tool! The Adapt team will consider all new feature requests, but unfortunately cannot commit to every one.
9
- - type: textarea
10
- id: description
11
- attributes:
12
- label: Feature description
13
- description: Please describe your feature request
14
- validations:
15
- required: true
16
- - type: checkboxes
17
- id: contribute
18
- attributes:
19
- label: Can you work on this feature?
20
- description: If you are able to commit your own time to work on this feature, it will greatly increase the liklihood of it being implemented by the core dev team. Otherwise, it will be triaged and prioritised alongside the core team's current priorities.
21
- options:
22
- - label: I can contribute
1
+ name: Feature request
2
+ description: Request a new feature
3
+ labels: ["enhancement"]
4
+ body:
5
+ - type: markdown
6
+ attributes:
7
+ value: |
8
+ Thanks for taking the time to request a new feature in the Adapt authoring tool! The Adapt team will consider all new feature requests, but unfortunately cannot commit to every one.
9
+ - type: textarea
10
+ id: description
11
+ attributes:
12
+ label: Feature description
13
+ description: Please describe your feature request
14
+ validations:
15
+ required: true
16
+ - type: checkboxes
17
+ id: contribute
18
+ attributes:
19
+ label: Can you work on this feature?
20
+ description: If you are able to commit your own time to work on this feature, it will greatly increase the liklihood of it being implemented by the core dev team. Otherwise, it will be triaged and prioritised alongside the core team's current priorities.
21
+ options:
22
+ - label: I can contribute
@@ -1,11 +1,11 @@
1
- # To get started with Dependabot version updates, you'll need to specify which
2
- # package ecosystems to update and where the package manifests are located.
3
- # Please see the documentation for all configuration options:
4
- # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5
-
6
- version: 2
7
- updates:
8
- - package-ecosystem: "npm" # See documentation for possible values
9
- directory: "/" # Location of package manifests
10
- schedule:
11
- interval: "weekly"
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "npm" # See documentation for possible values
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "weekly"
@@ -1,25 +1,25 @@
1
- [//]: # (Please title your PR according to eslint commit conventions)
2
- [//]: # (See https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-eslint#eslint-convention for details)
3
-
4
- [//]: # (Add a link to the original issue)
5
-
6
- [//]: # (Delete as appropriate)
7
- ### Fix
8
- * A sentence describing each fix
9
-
10
- ### Update
11
- * A sentence describing each udpate
12
-
13
- ### New
14
- * A sentence describing each new feature
15
-
16
- ### Breaking
17
- * A sentence describing each breaking change
18
-
19
- [//]: # (List appropriate steps for testing if needed)
20
- ### Testing
21
- 1. Steps for testing
22
-
23
- [//]: # (Mention any other dependencies)
24
-
25
-
1
+ [//]: # (Please title your PR according to eslint commit conventions)
2
+ [//]: # (See https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-eslint#eslint-convention for details)
3
+
4
+ [//]: # (Add a link to the original issue)
5
+
6
+ [//]: # (Delete as appropriate)
7
+ ### Fix
8
+ * A sentence describing each fix
9
+
10
+ ### Update
11
+ * A sentence describing each udpate
12
+
13
+ ### New
14
+ * A sentence describing each new feature
15
+
16
+ ### Breaking
17
+ * A sentence describing each breaking change
18
+
19
+ [//]: # (List appropriate steps for testing if needed)
20
+ ### Testing
21
+ 1. Steps for testing
22
+
23
+ [//]: # (Mention any other dependencies)
24
+
25
+
@@ -1,16 +1,16 @@
1
- name: Add labelled PRs to project
2
-
3
- on:
4
- pull_request:
5
- types: [ labeled ]
6
-
7
- jobs:
8
- add-to-project:
9
- if: ${{ github.event.label.name == 'dependencies' }}
10
- name: Add to main project
11
- runs-on: ubuntu-latest
12
- steps:
13
- - uses: actions/add-to-project@v0.1.0
14
- with:
15
- project-url: https://github.com/orgs/adapt-security/projects/5
16
- github-token: ${{ secrets.PROJECTS_SECRET }}
1
+ name: Add labelled PRs to project
2
+
3
+ on:
4
+ pull_request:
5
+ types: [ labeled ]
6
+
7
+ jobs:
8
+ add-to-project:
9
+ if: ${{ github.event.label.name == 'dependencies' }}
10
+ name: Add to main project
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/add-to-project@v0.1.0
14
+ with:
15
+ project-url: https://github.com/orgs/adapt-security/projects/5
16
+ github-token: ${{ secrets.PROJECTS_SECRET }}
@@ -1,19 +1,19 @@
1
- name: Add to main project
2
-
3
- on:
4
- issues:
5
- types:
6
- - opened
7
- pull_request:
8
- types:
9
- - opened
10
-
11
- jobs:
12
- add-to-project:
13
- name: Add to main project
14
- runs-on: ubuntu-latest
15
- steps:
16
- - uses: actions/add-to-project@v0.1.0
17
- with:
18
- project-url: https://github.com/orgs/adapt-security/projects/5
19
- github-token: ${{ secrets.PROJECTS_SECRET }}
1
+ name: Add to main project
2
+
3
+ on:
4
+ issues:
5
+ types:
6
+ - opened
7
+ pull_request:
8
+ types:
9
+ - opened
10
+
11
+ jobs:
12
+ add-to-project:
13
+ name: Add to main project
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/add-to-project@v0.1.0
17
+ with:
18
+ project-url: https://github.com/orgs/adapt-security/projects/5
19
+ github-token: ${{ secrets.PROJECTS_SECRET }}
@@ -0,0 +1,25 @@
1
+ name: Release
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+ jobs:
7
+ release:
8
+ name: Release
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - name: Checkout
12
+ uses: actions/checkout@v3
13
+ with:
14
+ fetch-depth: 0
15
+ - name: Setup Node.js
16
+ uses: actions/setup-node@v3
17
+ with:
18
+ node-version: 'lts/*'
19
+ - name: Install dependencies
20
+ run: npm ci
21
+ - name: Release
22
+ env:
23
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24
+ NPM_TOKEN: ${{ secrets.AAT_NPM_TOKEN }}
25
+ run: npx semantic-release
package/README.md CHANGED
@@ -1,2 +1,2 @@
1
- # adapt-authoring-errors
1
+ # adapt-authoring-errors
2
2
  Error handling for the Adapt authoring tool.
@@ -1,13 +1,13 @@
1
- {
2
- "essentialType": "errors",
3
- "documentation": {
4
- "enable": true,
5
- "manualPages": {
6
- "error-handling.md": "basics",
7
- "errorsref.md": "reference"
8
- },
9
- "manualPlugins": [
10
- "docs/plugins/errors.js"
11
- ]
12
- }
13
- }
1
+ {
2
+ "essentialType": "errors",
3
+ "documentation": {
4
+ "enable": true,
5
+ "manualPages": {
6
+ "error-handling.md": "basics",
7
+ "errorsref.md": "reference"
8
+ },
9
+ "manualPlugins": [
10
+ "docs/plugins/errors.js"
11
+ ]
12
+ }
13
+ }
@@ -1,50 +1,50 @@
1
- # Error handling
2
- Handling errors correctly is a key aspect of writing stable software. This guide will give some tips on how you should deal with errors, as well as the utilities available to make error handling simpler.
3
-
4
- Before going into specifics, it would be useful to discuss application errors in general terms. The errors you experience are likely to fall into one of the following broad groups:
5
- - **Initialisation errors**: i.e. problems during start-up
6
- - **General server errors**: errors which occur outside of user requests, possibly during automated tasks
7
- - **User errors**: errors which are a direct result of a user request
8
-
9
- You will need to deal with each category of error differently. Below are some general tips on handling each type of error.
10
-
11
- ## Initialisation errors
12
- ## Initialisation errors
13
- Any errors which occur during initialisation should be captured and logged as appropriate. Depending on the type of error, it may or may not be considered fatal to your code.
14
-
15
- Some examples:
16
- - For a database-handler module, failing to connect to the database would be considered a fatal error, as no further actions can be executed. In this case, the code should perform any clean-up and exit.
17
- - For a configuration module, failing to load the user configuration file may not be fatal if the application can run without it (e.g. with default settings). In this case the error should be logged, but the code can continue to initialise post-error.
18
- - For a module which attempts to load a specific file in each module connected to the core system, failing to load a single configuration file may not be an error as such, but rather an expected outcome if the configuration file in question is not something that's required to be defined for every module. In this case, the code can continue and it may not even be necessary to log a message.
19
-
20
- ## General server errors
21
- 'General server errors' is a broad category which covers other errors that don't take place at either initialisation or as a result of direct user action. Again, depending on the specific error, these may or may not be fatal.
22
-
23
- Some examples:
24
- - For a database-handler module, disconnecting from the database is an expected error, and can be handled and rectified easily.
25
-
26
- ## User errors errors
27
- User errors are any errors which are caused as a direct result of a user performing an action incorrectly. It is even *more* critical with user errors that the error is as specific and descriptive as possible, as the response needs to be informative and instructive to the user that caused the error. Failing to do so will result in an unpleasant user experience.
28
-
29
- Some examples:
30
- - A user uploads a file in an invalid format. This definitely isn't a fatal error, as the code can continue post-error. The returned error should inform the user of the issue, as well as how it can be rectified.
31
-
32
- ## Defining errors
33
- Depending on the kinds of error that you're dealing with in your code, it may be useful to include a set of custom error definitions specific to your code.
34
-
35
- Defining useful errors is a critical part of any software system. The ErrorsModule makes it easy to define errors for your own modules, and make use of errors defined in other modules.
36
-
37
- ## Catching errors
38
-
39
- ## Throwing errors
40
- As mentioned above, it is preferable to catch errors internally in your code and re-throw these errors
41
-
42
- The ErrorsModule acts as a central store for all errors defined in the system, and errors can be accessed and thrown from here. For convenience, the Errors module is made available directly as a property of the main App instance, or by referencing the module in the usual way: `App#waitForModule('errors)`
43
-
44
- ```js
45
- try {
46
- // do something here
47
- } catch(e) {
48
- throw this.app.errors.MY_ERROR
49
- }
1
+ # Error handling
2
+ Handling errors correctly is a key aspect of writing stable software. This guide will give some tips on how you should deal with errors, as well as the utilities available to make error handling simpler.
3
+
4
+ Before going into specifics, it would be useful to discuss application errors in general terms. The errors you experience are likely to fall into one of the following broad groups:
5
+ - **Initialisation errors**: i.e. problems during start-up
6
+ - **General server errors**: errors which occur outside of user requests, possibly during automated tasks
7
+ - **User errors**: errors which are a direct result of a user request
8
+
9
+ You will need to deal with each category of error differently. Below are some general tips on handling each type of error.
10
+
11
+ ## Initialisation errors
12
+ ## Initialisation errors
13
+ Any errors which occur during initialisation should be captured and logged as appropriate. Depending on the type of error, it may or may not be considered fatal to your code.
14
+
15
+ Some examples:
16
+ - For a database-handler module, failing to connect to the database would be considered a fatal error, as no further actions can be executed. In this case, the code should perform any clean-up and exit.
17
+ - For a configuration module, failing to load the user configuration file may not be fatal if the application can run without it (e.g. with default settings). In this case the error should be logged, but the code can continue to initialise post-error.
18
+ - For a module which attempts to load a specific file in each module connected to the core system, failing to load a single configuration file may not be an error as such, but rather an expected outcome if the configuration file in question is not something that's required to be defined for every module. In this case, the code can continue and it may not even be necessary to log a message.
19
+
20
+ ## General server errors
21
+ 'General server errors' is a broad category which covers other errors that don't take place at either initialisation or as a result of direct user action. Again, depending on the specific error, these may or may not be fatal.
22
+
23
+ Some examples:
24
+ - For a database-handler module, disconnecting from the database is an expected error, and can be handled and rectified easily.
25
+
26
+ ## User errors errors
27
+ User errors are any errors which are caused as a direct result of a user performing an action incorrectly. It is even *more* critical with user errors that the error is as specific and descriptive as possible, as the response needs to be informative and instructive to the user that caused the error. Failing to do so will result in an unpleasant user experience.
28
+
29
+ Some examples:
30
+ - A user uploads a file in an invalid format. This definitely isn't a fatal error, as the code can continue post-error. The returned error should inform the user of the issue, as well as how it can be rectified.
31
+
32
+ ## Defining errors
33
+ Depending on the kinds of error that you're dealing with in your code, it may be useful to include a set of custom error definitions specific to your code.
34
+
35
+ Defining useful errors is a critical part of any software system. The ErrorsModule makes it easy to define errors for your own modules, and make use of errors defined in other modules.
36
+
37
+ ## Catching errors
38
+
39
+ ## Throwing errors
40
+ As mentioned above, it is preferable to catch errors internally in your code and re-throw these errors
41
+
42
+ The ErrorsModule acts as a central store for all errors defined in the system, and errors can be accessed and thrown from here. For convenience, the Errors module is made available directly as a property of the main App instance, or by referencing the module in the usual way: `App#waitForModule('errors)`
43
+
44
+ ```js
45
+ try {
46
+ // do something here
47
+ } catch(e) {
48
+ throw this.app.errors.MY_ERROR
49
+ }
50
50
  ```
@@ -1,19 +1,19 @@
1
- export default class Errors {
2
- async run() {
3
- this.manualFile = 'errorsref.md';
4
- this.contents = Object.keys(this.app.errors);
5
- this.replace = { ERRORS: this.generateMd() };
6
- }
7
- generateMd() {
8
- return Object.keys(this.app.errors).reduce((md, k) => {
9
- const e = this.app.errors[k];
10
- return `${md}\n| \`${e.code}\` | ${e.meta.description} | ${e.statusCode} | <ul>${this.dataToMd(e.meta.data)}</ul> |`;
11
- }, '| Error code | Description | HTTP status code | Supplemental data |\n| - | - | :-: | - |');
12
- }
13
- dataToMd(data, s = '') {
14
- if(!data) return s;
15
- return Object.entries(data).reduce((s, [k, v]) => {
16
- return `${s}<li>\`${k}\`: ${typeof v === 'object' ? this.dataToMd(v, s) : v}</li>`;
17
- }, s);
18
- }
1
+ export default class Errors {
2
+ async run() {
3
+ this.manualFile = 'errorsref.md';
4
+ this.contents = Object.keys(this.app.errors);
5
+ this.replace = { ERRORS: this.generateMd() };
6
+ }
7
+ generateMd() {
8
+ return Object.keys(this.app.errors).reduce((md, k) => {
9
+ const e = this.app.errors[k];
10
+ return `${md}\n| \`${e.code}\` | ${e.meta.description} | ${e.statusCode} | <ul>${this.dataToMd(e.meta.data)}</ul> |`;
11
+ }, '| Error code | Description | HTTP status code | Supplemental data |\n| - | - | :-: | - |');
12
+ }
13
+ dataToMd(data, s = '') {
14
+ if(!data) return s;
15
+ return Object.entries(data).reduce((s, [k, v]) => {
16
+ return `${s}<li>\`${k}\`: ${typeof v === 'object' ? this.dataToMd(v, s) : v}</li>`;
17
+ }, s);
18
+ }
19
19
  }
@@ -1,9 +1,9 @@
1
- # Errors Reference
2
-
3
- This page documents all errors which are likely to be thrown in the system, along with the appropriate HTTP status code and any supplemental data which is stored with the error.
4
-
5
- Supplemental data can be used at the point that errors are translated to provide more context to a specific error. All data stored with an error can be assumed to be a primitive type for easy printing.
6
-
7
- {{{TABLE_OF_CONTENTS}}}
8
-
1
+ # Errors Reference
2
+
3
+ This page documents all errors which are likely to be thrown in the system, along with the appropriate HTTP status code and any supplemental data which is stored with the error.
4
+
5
+ Supplemental data can be used at the point that errors are translated to provide more context to a specific error. All data stored with an error can be assumed to be a primitive type for easy printing.
6
+
7
+ {{{TABLE_OF_CONTENTS}}}
8
+
9
9
  {{{ERRORS}}}
@@ -1,38 +1,38 @@
1
- {
2
- "FUNC_NOT_OVERRIDDEN": {
3
- "data": {
4
- "name": "The name of the function"
5
- },
6
- "description": "Function must be overridden in child class",
7
- "statusCode": 500
8
- },
9
- "FUNC_DISABLED": {
10
- "data": {
11
- "name": "The name of the function"
12
- },
13
- "description": "Function has been disabled",
14
- "statusCode": 500
15
- },
16
- "SERVER_ERROR": {
17
- "description": "Generic server error",
18
- "statusCode": 500,
19
- "data": {
20
- "error": "The original error"
21
- }
22
- },
23
- "INVALID_PARAMS": {
24
- "data": {
25
- "params": "The invalid params"
26
- },
27
- "description": "Invalid parameters have been provided",
28
- "statusCode": 400
29
- },
30
- "NOT_FOUND": {
31
- "data": {
32
- "id": "An identifier for the missing item",
33
- "type": "Type of the missing item"
34
- },
35
- "description": "Requested item could not be found",
36
- "statusCode": 404
37
- }
1
+ {
2
+ "FUNC_NOT_OVERRIDDEN": {
3
+ "data": {
4
+ "name": "The name of the function"
5
+ },
6
+ "description": "Function must be overridden in child class",
7
+ "statusCode": 500
8
+ },
9
+ "FUNC_DISABLED": {
10
+ "data": {
11
+ "name": "The name of the function"
12
+ },
13
+ "description": "Function has been disabled",
14
+ "statusCode": 500
15
+ },
16
+ "SERVER_ERROR": {
17
+ "description": "Generic server error",
18
+ "statusCode": 500,
19
+ "data": {
20
+ "error": "The original error"
21
+ }
22
+ },
23
+ "INVALID_PARAMS": {
24
+ "data": {
25
+ "params": "The invalid params"
26
+ },
27
+ "description": "Invalid parameters have been provided",
28
+ "statusCode": 400
29
+ },
30
+ "NOT_FOUND": {
31
+ "data": {
32
+ "id": "An identifier for the missing item",
33
+ "type": "Type of the missing item"
34
+ },
35
+ "description": "Requested item could not be found",
36
+ "statusCode": 404
37
+ }
38
38
  }
@@ -1,39 +1,39 @@
1
- {
2
- "EACCES": {
3
- "description": "An attempt was made to access a file in a way forbidden by its file access permissions",
4
- "statusCode": 500
5
- },
6
- "EADDRINUSE": {
7
- "description": "An attempt to bind a server to a local address failed due to another server on the local system already occupying that address",
8
- "statusCode": 500
9
- },
10
- "ECONNREFUSED": {
11
- "description": "No connection could be made because the target machine actively refused it",
12
- "statusCode": 500
13
- },
14
- "EEXIST": {
15
- "description": "An existing file was the target of an operation that required that the target not exist",
16
- "statusCode": 500,
17
- "data": {
18
- "path": "Path to target file or directory"
19
- }
20
- },
21
- "ENOENT": {
22
- "description": "No entity (file or directory) could be found by the given path",
23
- "statusCode": 500,
24
- "data": {
25
- "path": "Path to target file or directory"
26
- }
27
- },
28
- "ENOTEMPTY": {
29
- "description": "A directory with entries was the target of an operation that requires an empty directory",
30
- "statusCode": 500,
31
- "data": {
32
- "path": "Path to target file or directory"
33
- }
34
- },
35
- "MODULE_NOT_FOUND": {
36
- "description": "A module file could not be resolved while attempting a require() or import operation",
37
- "statusCode": 500
38
- }
1
+ {
2
+ "EACCES": {
3
+ "description": "An attempt was made to access a file in a way forbidden by its file access permissions",
4
+ "statusCode": 500
5
+ },
6
+ "EADDRINUSE": {
7
+ "description": "An attempt to bind a server to a local address failed due to another server on the local system already occupying that address",
8
+ "statusCode": 500
9
+ },
10
+ "ECONNREFUSED": {
11
+ "description": "No connection could be made because the target machine actively refused it",
12
+ "statusCode": 500
13
+ },
14
+ "EEXIST": {
15
+ "description": "An existing file was the target of an operation that required that the target not exist",
16
+ "statusCode": 500,
17
+ "data": {
18
+ "path": "Path to target file or directory"
19
+ }
20
+ },
21
+ "ENOENT": {
22
+ "description": "No entity (file or directory) could be found by the given path",
23
+ "statusCode": 500,
24
+ "data": {
25
+ "path": "Path to target file or directory"
26
+ }
27
+ },
28
+ "ENOTEMPTY": {
29
+ "description": "A directory with entries was the target of an operation that requires an empty directory",
30
+ "statusCode": 500,
31
+ "data": {
32
+ "path": "Path to target file or directory"
33
+ }
34
+ },
35
+ "MODULE_NOT_FOUND": {
36
+ "description": "A module file could not be resolved while attempting a require() or import operation",
37
+ "statusCode": 500
38
+ }
39
39
  }
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
- /**
2
- * Error handling
3
- * @namespace errors
4
- */
5
- export { default } from './lib/ErrorsModule.js'
1
+ /**
2
+ * Error handling
3
+ * @namespace errors
4
+ */
5
+ export { default } from './lib/ErrorsModule.js'
package/lib/AdaptError.js CHANGED
@@ -1,52 +1,52 @@
1
- /**
2
- * A generic error class for use in Adapt applications
3
- * @memberof errors
4
- */
5
- class AdaptError extends Error {
6
- /**
7
- * @constructor
8
- * @param {string} code The human-readable error code
9
- * @param {number} statusCode The HTTP status code
10
- * @param {object} metadata Metadata describing the error
11
- */
12
- constructor (code, statusCode = 500, metadata = {}) {
13
- super(code)
14
- /**
15
- * The error code
16
- * @type {String}
17
- */
18
- this.code = code
19
- /**
20
- * The HTTP status code
21
- * @type {String}
22
- */
23
- this.statusCode = statusCode
24
- /**
25
- * Metadata describing the error
26
- * @type {Object}
27
- */
28
- this.meta = metadata
29
- }
30
-
31
- /**
32
- * Chainable function to allow setting of data for use in user-friendly error messages later on.
33
- * @param {object} data
34
- * @returns {AdaptError}
35
- * @example
36
- * // note calling this function will also return
37
- * // the error itself to allow for easy error throwing
38
- * throw this.app.errors.MY_ERROR
39
- * .setData({ hello: 'world' })
40
- */
41
- setData (data) {
42
- this.data = data
43
- return this
44
- }
45
-
46
- /** @override */
47
- toString () {
48
- return `${this.constructor.name}: ${this.code} ${this.data ? JSON.stringify(this.data) : ''}`
49
- }
50
- }
51
-
52
- export default AdaptError
1
+ /**
2
+ * A generic error class for use in Adapt applications
3
+ * @memberof errors
4
+ */
5
+ class AdaptError extends Error {
6
+ /**
7
+ * @constructor
8
+ * @param {string} code The human-readable error code
9
+ * @param {number} statusCode The HTTP status code
10
+ * @param {object} metadata Metadata describing the error
11
+ */
12
+ constructor (code, statusCode = 500, metadata = {}) {
13
+ super(code)
14
+ /**
15
+ * The error code
16
+ * @type {String}
17
+ */
18
+ this.code = code
19
+ /**
20
+ * The HTTP status code
21
+ * @type {String}
22
+ */
23
+ this.statusCode = statusCode
24
+ /**
25
+ * Metadata describing the error
26
+ * @type {Object}
27
+ */
28
+ this.meta = metadata
29
+ }
30
+
31
+ /**
32
+ * Chainable function to allow setting of data for use in user-friendly error messages later on.
33
+ * @param {object} data
34
+ * @returns {AdaptError}
35
+ * @example
36
+ * // note calling this function will also return
37
+ * // the error itself to allow for easy error throwing
38
+ * throw this.app.errors.MY_ERROR
39
+ * .setData({ hello: 'world' })
40
+ */
41
+ setData (data) {
42
+ this.data = data
43
+ return this
44
+ }
45
+
46
+ /** @override */
47
+ toString () {
48
+ return `${this.constructor.name}: ${this.code} ${this.data ? JSON.stringify(this.data) : ''}`
49
+ }
50
+ }
51
+
52
+ export default AdaptError
@@ -1,58 +1,58 @@
1
- import { AbstractModule } from 'adapt-authoring-core'
2
- import AdaptError from './AdaptError.js'
3
- import fs from 'fs/promises'
4
- import { glob } from 'glob'
5
-
6
- /**
7
- * Module to store a global reference to all errors defined in the system. Errors are accessed from here and thrown appropriately elsewhere.
8
- * @memberof errors
9
- * @extends {AbstractModule}
10
- */
11
- class ErrorModule extends AbstractModule {
12
- /** @override */
13
- async init () {
14
- /**
15
- * A key/value store of all errors defined in the system. Errors are accessed via the human-readable error code for better readability when thrown in code.
16
- * @type {object}
17
- * @see {AdaptError}
18
- */
19
- this.errors = await this.loadErrors()
20
- this.app.errors = this.errors
21
- }
22
-
23
- /**
24
- * Loads all errors defined in Adapt module dependencies
25
- * @returns {Promise}
26
- */
27
- async loadErrors () {
28
- const errorDefs = {}
29
- await Promise.all(Object.values(this.app.dependencies).map(async d => {
30
- const files = await glob('errors/*.json', { cwd: d.rootDir, absolute: true })
31
- await Promise.all(files.map(async f => {
32
- try {
33
- const contents = JSON.parse(await fs.readFile(f))
34
- Object.entries(contents).forEach(([k, v]) => {
35
- if (errorDefs[k]) return this.log('warn', `error code '${k}' already defined`)
36
- errorDefs[k] = v
37
- })
38
- } catch (e) {
39
- this.log('error', e.message)
40
- }
41
- }))
42
- }))
43
- return Object.entries(errorDefs)
44
- .sort()
45
- .reduce((m, [k, { description, statusCode, data }]) => {
46
- return Object.defineProperty(m, k, {
47
- get: () => {
48
- const metadata = { description }
49
- if (data) metadata.data = data
50
- return new AdaptError(k, statusCode, metadata)
51
- },
52
- enumerable: true
53
- })
54
- }, {})
55
- }
56
- }
57
-
58
- export default ErrorModule
1
+ import { AbstractModule } from 'adapt-authoring-core'
2
+ import AdaptError from './AdaptError.js'
3
+ import fs from 'fs/promises'
4
+ import { glob } from 'glob'
5
+
6
+ /**
7
+ * Module to store a global reference to all errors defined in the system. Errors are accessed from here and thrown appropriately elsewhere.
8
+ * @memberof errors
9
+ * @extends {AbstractModule}
10
+ */
11
+ class ErrorModule extends AbstractModule {
12
+ /** @override */
13
+ async init () {
14
+ /**
15
+ * A key/value store of all errors defined in the system. Errors are accessed via the human-readable error code for better readability when thrown in code.
16
+ * @type {object}
17
+ * @see {AdaptError}
18
+ */
19
+ this.errors = await this.loadErrors()
20
+ this.app.errors = this.errors
21
+ }
22
+
23
+ /**
24
+ * Loads all errors defined in Adapt module dependencies
25
+ * @returns {Promise}
26
+ */
27
+ async loadErrors () {
28
+ const errorDefs = {}
29
+ await Promise.all(Object.values(this.app.dependencies).map(async d => {
30
+ const files = await glob('errors/*.json', { cwd: d.rootDir, absolute: true })
31
+ await Promise.all(files.map(async f => {
32
+ try {
33
+ const contents = JSON.parse(await fs.readFile(f))
34
+ Object.entries(contents).forEach(([k, v]) => {
35
+ if (errorDefs[k]) return this.log('warn', `error code '${k}' already defined`)
36
+ errorDefs[k] = v
37
+ })
38
+ } catch (e) {
39
+ this.log('error', e.message)
40
+ }
41
+ }))
42
+ }))
43
+ return Object.entries(errorDefs)
44
+ .sort()
45
+ .reduce((m, [k, { description, statusCode, data }]) => {
46
+ return Object.defineProperty(m, k, {
47
+ get: () => {
48
+ const metadata = { description }
49
+ if (data) metadata.data = data
50
+ return new AdaptError(k, statusCode, metadata)
51
+ },
52
+ enumerable: true
53
+ })
54
+ }, {})
55
+ }
56
+ }
57
+
58
+ export default ErrorModule
package/package.json CHANGED
@@ -1,17 +1,52 @@
1
- {
2
- "name": "adapt-authoring-errors",
3
- "version": "0.0.1",
4
- "description": "Error handling for the Adapt authoring tool",
5
- "homepage": "https://github.com/adapt-security/adapt-authoring-errors",
6
- "license": "GPL-3.0",
7
- "type": "module",
8
- "main": "index.js",
9
- "repository": "github:adapt-security/adapt-authoring-errors",
10
- "devDependencies": {
11
- "eslint": "^9.9.1",
12
- "standard": "^17.1.0"
13
- },
14
- "dependencies": {
15
- "glob": "^11.0.0"
16
- }
17
- }
1
+ {
2
+ "name": "adapt-authoring-errors",
3
+ "version": "1.0.0",
4
+ "description": "Error handling for the Adapt authoring tool",
5
+ "homepage": "https://github.com/adapt-security/adapt-authoring-errors",
6
+ "license": "GPL-3.0",
7
+ "type": "module",
8
+ "main": "index.js",
9
+ "repository": "github:adapt-security/adapt-authoring-errors",
10
+ "devDependencies": {
11
+ "eslint": "^9.9.1",
12
+ "standard": "^17.1.0",
13
+ "@semantic-release/commit-analyzer": "^9.0.2",
14
+ "@semantic-release/git": "^10.0.1",
15
+ "@semantic-release/github": "^8.0.5",
16
+ "@semantic-release/npm": "^9.0.1",
17
+ "@semantic-release/release-notes-generator": "^10.0.3",
18
+ "conventional-changelog-eslint": "^3.0.9",
19
+ "semantic-release": "^21.0.1",
20
+ "semantic-release-replace-plugin": "^1.2.7"
21
+ },
22
+ "release": {
23
+ "plugins": [
24
+ [
25
+ "@semantic-release/commit-analyzer",
26
+ {
27
+ "preset": "eslint"
28
+ }
29
+ ],
30
+ [
31
+ "@semantic-release/release-notes-generator",
32
+ {
33
+ "preset": "eslint"
34
+ }
35
+ ],
36
+ "@semantic-release/npm",
37
+ "@semantic-release/github",
38
+ [
39
+ "@semantic-release/git",
40
+ {
41
+ "assets": [
42
+ "package.json"
43
+ ],
44
+ "message": "Chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
45
+ }
46
+ ]
47
+ ]
48
+ },
49
+ "dependencies": {
50
+ "glob": "^11.0.0"
51
+ }
52
+ }