Skip to content

Decode as UTF-8 in ExitCodeException's Show instance #89

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

9999years
Copy link
Contributor

Partial fix for #86. This isn't perfect (for retrocomputing you may want another character encoding) but improves the behavior in many circumstances.

Requires #88.

Split off of fpco#83.

Before, `ProcessConfig`'s `Show` output would include a trailing
newline. This has been fixed, so that derived `Show` output does not
include newlines in weird places.

Before:

    ghci> data Foo = Foo { a :: Int, b :: ProcessConfig () () (), c :: String } deriving Show
    ghci> Foo 1 (proc "echo" ["puppy"]) "doggy"
    Foo {a = 1, b = Raw command: echo puppy
    , c = "doggy"}

After

    ghci> Foo 1 (proc "echo" ["puppy"]) "doggy"
    Foo {a = 1, b = Raw command: echo puppy, c = "doggy"}

Whitespace for the `ExitCodeException` `Show` instance has also been
adjusted, to place the output closer to the relevant headers.

Before:

    ghci> readProcess_ $ proc "sh" ["-c", "echo this is stdout; echo this is stderr >&2; false"]
    *** Exception: Received ExitFailure 1 when running
    Raw command: sh -c "echo this is stdout; echo this is stderr >&2; false"
    Standard output:

    this is stdout
    Standard error:

    this is stderr

After:

    *** Exception: Received ExitFailure 1 when running
    Raw command: sh -c "echo this is stdout; echo this is stderr >&2; false"

    Standard output:
    this is stdout

    Standard error:
    this is stderr

Note that because trailing whitespace is not accounted for, it is still
possible to get unintuitive results depending on what exactly the
subprocess prints:

    ghci> readProcess_ $ proc "sh" ["-c", "echo -n this is stdout; echo -n this is stderr >&2; false"]
    *** Exception: Received ExitFailure 1 when running
    Raw command: sh -c "echo -n this is stdout; echo -n this is stderr >&2; false"

    Standard output:
    this is stdout
    Standard error:
    this is stderr
@9999years 9999years force-pushed the exitcodeexception-utf8 branch from b105d12 to c381613 Compare April 8, 2025 20:13
Partial fix for fpco#86. This isn't perfect (for retrocomputing you may want
another character encoding) but improves the behavior in many
circumstances.
@9999years 9999years force-pushed the exitcodeexception-utf8 branch from c381613 to 9fc7dc1 Compare April 8, 2025 20:20
@tomjaguarpaw
Copy link
Collaborator

Could you please check whether #87 does what you want regarding UTF-8 decoding when formatting an ExitCodeException? It's more or less what you've already written, but minimized a bit.

@9999years
Copy link
Contributor Author

This PR is a draft which requires #88, let's discuss this PR after that one is closed.

@tomjaguarpaw
Copy link
Collaborator

I'd prefer to proceed directly to resolving the UTF-8 issue via #87, and would like to confirm you're content with that resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants