Skip to content

Commit 5aef8a3

Browse files
(GH-407) Support negative integers in manifest exitCodes
Prior to this change, the JSON schema for the `exitCodes` property of resource manifests only supported positive integers as exit codes. DSC itself supports negative integers as exit codes, and some apps return negative integers as exit codes for hexadecimal exit codes, like `-2147024891` for `0x80070005`, "Access denied." This change: - Updates both the source and composed schemas to allow negative integers. - Updates the reference documentation to clarify that you must specify integers, that you can't use any alternate formats for those integers, and that the keys in YAML must be wrapped in quotes for parsing. - Addresses #407 by making the schema compliant with the implementation.
1 parent 0157276 commit 5aef8a3

File tree

7 files changed

+41
-18
lines changed

7 files changed

+41
-18
lines changed

docs/reference/schemas/resource/manifest/root.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,26 @@ information, see the [DSC Resource manifest provider property schema reference][
229229
The `exitCodes` property defines a set of valid exit codes for the resource and their meaning.
230230
Define this property as a set of key-value pairs where:
231231

232-
- The key is a string containing an integer that maps to a known exit code for the resource.
232+
- The key is a string containing an integer that maps to a known exit code for the resource. You
233+
can't use alternate formats for the exit code. For example, instead of the hexadecimal value
234+
`0x80070005` for "Access denied", specify the exit code as `-2147024891`.
233235
- The value is a string describing the semantic meaning of that exit code for a human reader.
234236

235237
DSC interprets exit code `0` as a successful operation and any other exit code as an error.
236238

239+
> [!TIP]
240+
> If you're authoring your resource manifest in yaml, be sure to wrap the exit code in single
241+
> quotes to ensure the YAML file can be parsed correctly. For example:
242+
>
243+
> ```yaml
244+
> exitCodes:
245+
> '0': Success
246+
> '1': Invalid parameter
247+
> '2': Invalid input
248+
> '3': Registry error
249+
> '4': JSON serialization failed
250+
> ```
251+
237252
```yaml
238253
Type: object
239254
Required: false

schemas/2024/04/bundled/outputs/resource/list.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@
219219
"description": "This property defines a map of valid exit codes for the DSC Resource. DSC always interprets exit code `0` as a successful operation and any other exit code as an error. Use this property to indicate human-readable semantic meanings for the DSC Resource's exit codes.",
220220
"type": "object",
221221
"propertyNames": {
222-
"pattern": "^[0-9]+$"
222+
"pattern": "^-?[0-9]+$"
223223
},
224224
"patternProperties": {
225-
"^[0-9]+$": {
225+
"^-?[0-9]+$": {
226226
"type": "string"
227227
}
228228
},

schemas/2024/04/bundled/outputs/resource/list.vscode.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,11 @@
535535
"description": "This property defines a map of valid exit codes for the DSC Resource. DSC always interprets exit code `0` as a successful operation and any other exit code as an error. Use this property to indicate human-readable semantic meanings for the DSC Resource's exit codes.",
536536
"type": "object",
537537
"propertyNames": {
538-
"pattern": "^[0-9]+$",
539-
"patternErrorMessage": "Invalid exit code. Must be a string representing an integer greater than or equal to `0`.\n"
538+
"pattern": "^-?[0-9]+$",
539+
"patternErrorMessage": "Invalid exit code. Must be a string representing a 32-bit signed integer.\n"
540540
},
541541
"patternProperties": {
542-
"^[0-9]+$": {
542+
"^-?[0-9]+$": {
543543
"type": "string"
544544
}
545545
},
@@ -557,7 +557,7 @@
557557
"4": "JSON serialization failed"
558558
}
559559
],
560-
"markdownDescription": "***\n[_Online Documentation_][01]\n***\n\nThis property defines a map of valid exit codes for the DSC Resource. DSC always interprets\nexit code `0` as a successful operation and any other exit code as an error. Use this\nproperty to indicate human-readable semantic meanings for the DSC Resource's exit codes.\n\n[01]: https://learn.microsoft.com/powershell/dsc/reference/schemas/resource/manifest/root?view=dsc-3.0&preserve-view=true#exitcodes\n",
560+
"markdownDescription": "***\n[_Online Documentation_][01]\n***\n\nThis property defines a map of valid exit codes for the DSC Resource. DSC always interprets\nexit code `0` as a successful operation and any other exit code as an error. Use this\nproperty to indicate human-readable semantic meanings for the DSC Resource's exit codes.\n\nDefine the keys in this property as strings representing a valid 32-bit signed integer. You\ncan't use alternate formats for the exit code. For example, instead of the hexadecimal value\n`0x80070005` for \"Access denied\", specify the exit code as `-2147024891`. If you're authoring\nyour resource manifest in yaml, be sure to wrap the exit code in single quotes, like\n`'0': Success` instead of `0: Success` to ensure the YAML file can be parsed correctly.\n\nDefine the value for each key as a string explaining what the exit code indicates.\n\n[01]: https://learn.microsoft.com/powershell/dsc/reference/schemas/resource/manifest/root?view=dsc-3.0&preserve-view=true#exitcodes\n",
561561
"defaultSnippets": [
562562
{
563563
"label": " Defined exit codes",

schemas/2024/04/bundled/resource/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@
8080
"description": "This property defines a map of valid exit codes for the DSC Resource. DSC always interprets exit code `0` as a successful operation and any other exit code as an error. Use this property to indicate human-readable semantic meanings for the DSC Resource's exit codes.",
8181
"type": "object",
8282
"propertyNames": {
83-
"pattern": "^[0-9]+$"
83+
"pattern": "^-?[0-9]+$"
8484
},
8585
"patternProperties": {
86-
"^[0-9]+$": {
86+
"^-?[0-9]+$": {
8787
"type": "string"
8888
}
8989
},

schemas/2024/04/bundled/resource/manifest.vscode.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,11 @@
287287
"description": "This property defines a map of valid exit codes for the DSC Resource. DSC always interprets exit code `0` as a successful operation and any other exit code as an error. Use this property to indicate human-readable semantic meanings for the DSC Resource's exit codes.",
288288
"type": "object",
289289
"propertyNames": {
290-
"pattern": "^[0-9]+$",
291-
"patternErrorMessage": "Invalid exit code. Must be a string representing an integer greater than or equal to `0`.\n"
290+
"pattern": "^-?[0-9]+$",
291+
"patternErrorMessage": "Invalid exit code. Must be a string representing a 32-bit signed integer.\n"
292292
},
293293
"patternProperties": {
294-
"^[0-9]+$": {
294+
"^-?[0-9]+$": {
295295
"type": "string"
296296
}
297297
},
@@ -309,7 +309,7 @@
309309
"4": "JSON serialization failed"
310310
}
311311
],
312-
"markdownDescription": "***\n[_Online Documentation_][01]\n***\n\nThis property defines a map of valid exit codes for the DSC Resource. DSC always interprets\nexit code `0` as a successful operation and any other exit code as an error. Use this\nproperty to indicate human-readable semantic meanings for the DSC Resource's exit codes.\n\n[01]: https://learn.microsoft.com/powershell/dsc/reference/schemas/resource/manifest/root?view=dsc-3.0&preserve-view=true#exitcodes\n",
312+
"markdownDescription": "***\n[_Online Documentation_][01]\n***\n\nThis property defines a map of valid exit codes for the DSC Resource. DSC always interprets\nexit code `0` as a successful operation and any other exit code as an error. Use this\nproperty to indicate human-readable semantic meanings for the DSC Resource's exit codes.\n\nDefine the keys in this property as strings representing a valid 32-bit signed integer. You\ncan't use alternate formats for the exit code. For example, instead of the hexadecimal value\n`0x80070005` for \"Access denied\", specify the exit code as `-2147024891`. If you're authoring\nyour resource manifest in yaml, be sure to wrap the exit code in single quotes, like\n`'0': Success` instead of `0: Success` to ensure the YAML file can be parsed correctly.\n\nDefine the value for each key as a string explaining what the exit code indicates.\n\n[01]: https://learn.microsoft.com/powershell/dsc/reference/schemas/resource/manifest/root?view=dsc-3.0&preserve-view=true#exitcodes\n",
313313
"defaultSnippets": [
314314
{
315315
"label": " Defined exit codes",

schemas/2024/04/resource/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@
8080
"description": "This property defines a map of valid exit codes for the DSC Resource. DSC always interprets exit code `0` as a successful operation and any other exit code as an error. Use this property to indicate human-readable semantic meanings for the DSC Resource's exit codes.",
8181
"type": "object",
8282
"propertyNames": {
83-
"pattern": "^[0-9]+$"
83+
"pattern": "^-?[0-9]+$"
8484
},
8585
"patternProperties": {
86-
"^[0-9]+$": {
86+
"^-?[0-9]+$": {
8787
"type": "string"
8888
}
8989
},

schemas/src/resource/manifest.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,11 @@ properties:
444444
property to indicate human-readable semantic meanings for the DSC Resource's exit codes.
445445
type: object
446446
propertyNames:
447-
pattern: "^[0-9]+$"
447+
pattern: "^-?[0-9]+$"
448448
patternErrorMessage: |
449-
Invalid exit code. Must be a string representing an integer greater than or equal to `0`.
449+
Invalid exit code. Must be a string representing a 32-bit signed integer.
450450
patternProperties:
451-
"^[0-9]+$":
451+
"^-?[0-9]+$":
452452
type: string
453453
unevaluatedProperties: false
454454
default:
@@ -470,6 +470,14 @@ properties:
470470
exit code `0` as a successful operation and any other exit code as an error. Use this
471471
property to indicate human-readable semantic meanings for the DSC Resource's exit codes.
472472
473+
Define the keys in this property as strings representing a valid 32-bit signed integer. You
474+
can't use alternate formats for the exit code. For example, instead of the hexadecimal value
475+
`0x80070005` for "Access denied", specify the exit code as `-2147024891`. If you're authoring
476+
your resource manifest in yaml, be sure to wrap the exit code in single quotes, like
477+
`'0': Success` instead of `0: Success` to ensure the YAML file can be parsed correctly.
478+
479+
Define the value for each key as a string explaining what the exit code indicates.
480+
473481
[01]: <DOCS_BASE_URL>/reference/schemas/resource/manifest/root?<DOCS_VERSION_PIN>#exitcodes
474482
defaultSnippets:
475483
- label: ' Defined exit codes'

0 commit comments

Comments
 (0)