@adaas/a-concept 0.1.30 → 0.1.31

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaas/a-concept",
3
- "version": "0.1.30",
3
+ "version": "0.1.31",
4
4
  "description": "A-Concept is a framework to build new Applications within or outside the ADAAS ecosystem. This framework is designed to be modular structure regardless environment and program goal.",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.cjs",
@@ -330,16 +330,30 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
330
330
  */
331
331
  scope?: A_Scope,
332
332
  ) {
333
- if (this.isDone)
334
- return;
333
+ try {
334
+ if (scope && !scope.isInheritedFrom(A_Context.scope(this)))
335
+ scope.inherit(A_Context.scope(this));
335
336
 
336
- this._state = A_TYPES__FeatureState.PROCESSING;
337
337
 
338
- for (const stage of this) {
339
- await stage.process(scope);
338
+ if (this.isDone)
339
+ return;
340
+
341
+ this._state = A_TYPES__FeatureState.PROCESSING;
342
+
343
+ for (const stage of this) {
344
+ await stage.process(scope);
345
+ }
346
+
347
+ return await this.completed();
348
+ } catch (error) {
349
+ return await this.failed(new A_FeatureError({
350
+ title: A_FeatureError.FeatureProcessingError,
351
+ description: `An error occurred while processing the A-Feature: ${this.name}. Failed at stage: ${this.stage?.name || 'N/A'}.`,
352
+ stage: this.stage,
353
+ originalError: error
354
+ }));
340
355
  }
341
356
 
342
- return await this.completed();
343
357
  }
344
358
  /**
345
359
  * This method moves the feature to the next stage
@@ -368,6 +382,22 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
368
382
 
369
383
  this.scope.destroy();
370
384
  }
385
+ /**
386
+ * This method marks the feature as failed and throws an error
387
+ * Uses to mark the feature as failed
388
+ *
389
+ * @param error
390
+ */
391
+ async failed(error: A_FeatureError) {
392
+
393
+ this._state = A_TYPES__FeatureState.FAILED;
394
+
395
+ this._error = error;
396
+
397
+ this.scope.destroy();
398
+
399
+ throw this._error;
400
+ }
371
401
  /**
372
402
  * This method marks the feature as failed and throws an error
373
403
  * Uses to interrupt or end the feature processing
@@ -390,6 +420,7 @@ export class A_Feature<T extends A_TYPES__FeatureAvailableComponents = A_TYPES__
390
420
  code: A_FeatureError.Interruption,
391
421
  title: reason.title,
392
422
  description: reason.description,
423
+ stage: this.stage,
393
424
  originalError: reason
394
425
  });
395
426
  break;
@@ -1,8 +1,10 @@
1
1
  import { A_Error } from "../A-Error/A_Error.class";
2
+ import { A_Stage } from "../A-Stage/A-Stage.class";
3
+ import { A_TYPES__FeatureError_Init } from "./A-Feature.types";
2
4
 
3
5
 
4
6
 
5
- export class A_FeatureError extends A_Error {
7
+ export class A_FeatureError extends A_Error<A_TYPES__FeatureError_Init> {
6
8
 
7
9
  /**
8
10
  * Indicates that the Feature has been interrupted
@@ -14,6 +16,12 @@ export class A_FeatureError extends A_Error {
14
16
  * Failed during the A-Feature initialization process
15
17
  */
16
18
  static readonly FeatureInitializationError = 'Unable to initialize A-Feature';
19
+ /**
20
+ * Indicates that there was an error processing the Feature
21
+ *
22
+ * Failed during the A-Feature processing
23
+ */
24
+ static readonly FeatureProcessingError = 'Error occurred during A-Feature processing';
17
25
 
18
26
  // =======================================================================
19
27
  // ---------------------- Decorator Errors -----------------------------
@@ -30,4 +38,17 @@ export class A_FeatureError extends A_Error {
30
38
  * Failed during the @A_Feature.Extend() decorator execution
31
39
  */
32
40
  static readonly FeatureExtensionError = 'Unable to extend A-Feature';
41
+
42
+
43
+ /**
44
+ * Stage where the error occurred
45
+ */
46
+ stage?: A_Stage
47
+
48
+
49
+ protected fromConstructor(params: A_TYPES__FeatureError_Init): void {
50
+ super.fromConstructor(params);
51
+
52
+ this.stage = params.stage;
53
+ }
33
54
  }
@@ -9,6 +9,8 @@ import { A_TYPES__Entity_Constructor } from "../A-Entity/A-Entity.types"
9
9
  import { A_Feature } from "./A-Feature.class"
10
10
  import { A_TYPES__Required } from "@adaas/a-concept/types/A_Common.types"
11
11
  import { A_Scope } from "../A-Scope/A-Scope.class"
12
+ import { A_Stage } from "../A-Stage/A-Stage.class"
13
+ import { A_TYPES__Error_Init } from "../A-Error/A_Error.types"
12
14
 
13
15
 
14
16
  // ============================================================================
@@ -99,8 +101,26 @@ export enum A_TYPES__FeatureState {
99
101
  * The feature has been interrupted
100
102
  */
101
103
  INTERRUPTED = "INTERRUPTED",
104
+ /**
105
+ * The feature has failed
106
+ */
107
+ FAILED = "FAILED"
102
108
  }
103
109
 
110
+ // ===========================================================================
111
+ // --------------------------- Error Types ------------------------------------
112
+ // ===========================================================================
113
+
114
+ export type A_TYPES__FeatureError_Init = {
115
+ /**
116
+ * Stage where the error occurred
117
+ */
118
+ stage?: A_Stage
119
+
120
+ } & A_TYPES__Error_Init
121
+
122
+
123
+
104
124
  // ===========================================================================-
105
125
  // --------------------------- Available Types -------------------------------
106
126
  // ===========================================================================