Skip to content
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

Extend exitCodes to support Hexidecimal error codes #407

Open
joshcorr opened this issue Apr 15, 2024 · 1 comment
Open

Extend exitCodes to support Hexidecimal error codes #407

joshcorr opened this issue Apr 15, 2024 · 1 comment
Labels
Doc-Impact Issue-Bug Something isn't working Schema-Impact Change requires updating a canonical schema for configs or manifests

Comments

@joshcorr
Copy link

Summary of the new feature / enhancement

While I was playing around an idea for a DSC Resource, I received Exit code -2147024891 (0x80070005) Access Denied when trying to execute a binary which required elevation. I tried to represent this error in the exitCodes section of a DSC Resource manifest, but it does not appear to match the regex that dsc is using to validated exitCodes.

The feature request is that the regex be updated to support negative/Hexidecimal exit codes.

Proposed technical implementation details (optional)

No response

@michaeltlombardi
Copy link
Collaborator

You're correct, the JSON Schema forbids non-integers for the property names in the definition of exitCodes:

title: Exit Codes
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.
type: object
propertyNames:
pattern: "^[0-9]+$"
patternErrorMessage: |
Invalid exit code. Must be a string representing an integer greater than or equal to `0`.
patternProperties:
"^[0-9]+$":
type: string

The implementation for DSC expects the exit codes to be an integer:

/// Mapping of exit codes to descriptions. Zero is always success and non-zero is always failure.
#[serde(rename = "exitCodes", skip_serializing_if = "Option::is_none")]
pub exit_codes: Option<HashMap<i32, String>>,

You can add the following repro manifest to your path to see how DSC behaves:

{
    "$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/bundled/resource/manifest.json",
    "type": "DSC.Repro/Example",
    "version": "0.1.0",
    "description": "Repro behavior when exit codes are hexadecimal.",
    "get": {
        "executable": "repro",
        "input": "stdin"
    },
    "schema": {
        "command": {
            "executable": "repro",
            "args": [
                "--schema"
            ]
        }
    },
    "exitCodes": {
        "0": "Success",
        "1": "Error",
        "-2147024891": "testing hexadecimal as integer"
    }
}
dsc resource list DSC.Repro/Example

dsc resource list DSC.Repro/Example
| ConvertFrom-Json
| Select-Object -ExpandProperty manifest
| Select-Object -ExpandProperty exitCodes
| ConvertTo-Json
Type               Kind      Version  Caps    RequireAdapter  Description
-------------------------------------------------------------------------------------------------------------
DSC.Repro/Example  Resource  0.1.0    g-----                  Repro behavior when exit codes are hexadecimal.

{
  "0": "Success",
  "1": "Error",
  "-2147024891": "testing hexadecimal as integer"
}

However, if you update the manifest to use hex format for the exit code:

{
    // ... rest of the manifest
    "exitCodes": {
        "0": "Success",
        "1": "Error",
        "-2147024891": "testing hexadecimal as integer",
        "0x80070005": "testing hexadecimal as hex format"
    }
}

DSC raises an error - it doesn't have any built-in handling for converting the string 0x80070005 into the integer -2147024891 when reading in the JSON to the struct.

dsc resource list DSC.Repro/Example
2024-04-17T14:28:27.325654Z  WARN Manifest: C:\code\pwsh\DSCv3\bin\debug\repro.dsc.resource.json
JSON: expected `"` at line 22 column 11

Type  Kind  Version  Caps  RequireAdapter  Description
------------------------------------------------------

I can definitely update the schema definitions to allow negative integers, but unless the source code for DSC is updated, I can't update it to allow numbers in hexadecimal format.

michaeltlombardi added a commit to michaeltlombardi/DSC that referenced this issue Apr 17, 2024
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 PowerShell#407 by making the schema compliant with the implementation.
@michaeltlombardi michaeltlombardi added Issue-Bug Something isn't working Doc-Impact Schema-Impact Change requires updating a canonical schema for configs or manifests labels Apr 17, 2024
michaeltlombardi added a commit to michaeltlombardi/DSC that referenced this issue Apr 18, 2024
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 PowerShell#407 by making the schema compliant with the implementation.
michaeltlombardi added a commit to michaeltlombardi/DSC that referenced this issue Apr 18, 2024
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 PowerShell#407 by making the schema compliant with the implementation.
SteveL-MSFT added a commit to michaeltlombardi/DSC that referenced this issue Apr 23, 2024
michaeltlombardi added a commit to michaeltlombardi/DSC that referenced this issue Apr 29, 2024
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 PowerShell#407 by making the schema compliant with the implementation.
michaeltlombardi added a commit to michaeltlombardi/DSC that referenced this issue Apr 29, 2024
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 PowerShell#407 by making the schema compliant with the implementation.
github-merge-queue bot pushed a commit that referenced this issue May 2, 2024
…-code-schemas

(GH-407) Support negative integers in manifest `exitCodes`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Doc-Impact Issue-Bug Something isn't working Schema-Impact Change requires updating a canonical schema for configs or manifests
Projects
None yet
Development

No branches or pull requests

2 participants