Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit b7d5cd0

Browse files
authored
Update Exception Handling Design Doc (#465)
1 parent d5a8cc3 commit b7d5cd0

File tree

2 files changed

+74
-19
lines changed

2 files changed

+74
-19
lines changed

guides/command-implementation.md

+27
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,31 @@ E.g.
109109
> Value for organization name option was missing. Provide value for this option.
110110
111111
2. We do not want pronoun in error messages. E.g.
112+
112113
> You did not enter value for organization name. Please provide value for it.
114+
115+
3. All error shall be created with the error builder,
116+
https://github.com/CatalystCode/spk/blob/master/src/lib/errorBuilder.ts so
117+
that we can generate the exception chain. In this manner, we can precisely
118+
know the root cause of the problem. Error shall be logged at the end of the
119+
command like this
120+
121+
```
122+
export const execute = async (
123+
config: ConfigYaml,
124+
opts: CommandOptions,
125+
exitFn: (status: number) => Promise<void>
126+
): Promise<void> => {
127+
try {
128+
...;
129+
await exitFn(0);
130+
} catch (err) {
131+
logError(
132+
buildError(errorStatusCode.CMD_EXE_ERR, "infra-scaffold-cmd-failed", err)
133+
);
134+
await exitFn(1);
135+
}
136+
};
137+
```
138+
139+
[Reference](../technical-docs/designs/exceptionHandling.md)

technical-docs/designs/exceptionHandling.md

+47-19
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
Reference: Exception Handling<br> Authors: Andre Briggs, Dennis Seah
44

5-
| Revision | Date | Author | Remarks |
6-
| -------: | ------------ | ----------- | -------------------------------- |
7-
| 0.1 | Mar-04, 2020 | Dennis Seah | Initial Draft |
8-
| 1.0 | Mar-10, 2020 | Dennis Seah | Incorporate comments from Yvonne |
5+
| Revision | Date | Author | Remarks |
6+
| -------: | ------------ | ----------- | ------------------------------------------------- |
7+
| 0.1 | Mar-04, 2020 | Dennis Seah | Initial Draft |
8+
| 1.0 | Mar-10, 2020 | Dennis Seah | Incorporate comments from Yvonne |
9+
| 1.1 | Mar-27, 2020 | Dennis Seah | Amendments after first implementation is reviewed |
910

1011
## 1. Overview
1112

@@ -87,13 +88,15 @@ web client call. We would like to have a JSON object like this
8788

8889
```
8990
{
90-
"statusCode": 101,
91+
"errorCode": 1000,
9192
"message": "Execution of spk project install-lifecycle-pipeline could not be completed.",
92-
"error": {
93-
"message": "Execute of installPipeline function failed."
94-
"error": {
95-
"statusCode": 401,
96-
"message": "Unauthorized access to pipeline...."
93+
"parent": {
94+
"errorCode": 1010,
95+
"message": "Execute of installPipeline function failed.",
96+
"parent": {
97+
"errorCode": 1011,
98+
"message": "Unauthorized access to pipeline....",
99+
"details": "<exception message>"
97100
}
98101
}
99102
}
@@ -106,22 +109,47 @@ The typescript interface of this ErrorChain is
106109

107110
```
108111
interface ErrorChain {
109-
statusCode?: number;
112+
errorCode?: number;
110113
message: string;
111-
error?: ErrorChain;
114+
details: string | undefined;
115+
parent?: ErrorChain | undefined;
112116
}
113117
```
114118

115119
### 3.3 List of error codes
116120

117-
To be completed
121+
Example of `enum` of status code
118122

119-
| Error Code | Description |
120-
| ---------: | --------------------------------- |
121-
| 101 | Execution of command failed |
122-
| 110 | Validation of input values failed |
123-
| 201 | Azure pipeline API call failed |
124-
| ... | ... |
123+
```typescript
124+
export enum errorStatusCode {
125+
CMD_EXE_ERR = 1000,
126+
VALIDATION_ERR = 1001,
127+
EXE_FLOW_ERR = 1002,
128+
ENV_SETTING_ERR = 1010,
129+
GIT_OPS_ERR = 1100,
130+
}
131+
```
132+
133+
### 3.4 Externalization of error messsage
134+
135+
Example:
136+
137+
```json
138+
"errors": {
139+
"infra-scaffold-cmd-failed": "Scaffold Command was not successfully executed.",
140+
"infra-scaffold-cmd-src-missing": "Value for source is required because it cannot be constructed with properties in spk-config.yaml. Provide value for source.",
141+
"infra-scaffold-cmd-values-missing": "Values for name, version and/or 'template were missing. Provide value for values for them.",
142+
"infra-err-validating-remote-git": "Could not determine error when validating remote git source.",
143+
"infra-err-retry-validating-remote-git": "Failure error thrown during retrying validating remote git source.",
144+
"infra-err-locate-tf-env": "Could not find Terraform environment. Ensure template path {0} exists.",
145+
"infra-err-tf-path-not-found": "Provided Terraform {0} path is invalid or cannot be found: {1}",
146+
"infra-err-create-scaffold": "Could not create scaffold",
147+
"infra-err-git-clone-failed": "Could not clone the source remote repository. The remote repo might not exist or you did not have the rights to access it",
148+
"infra-git-source-no-exist": "Source path, {0} did not exist."
149+
}
150+
```
151+
152+
This allows us to localized error messages if needed.
125153

126154
## 4. Dependencies
127155

0 commit comments

Comments
 (0)