Skip to content

Misc refactors#1340

Open
Jimbo4350 wants to merge 3 commits intomasterfrom
jordan/misc-refactors-20260220
Open

Misc refactors#1340
Jimbo4350 wants to merge 3 commits intomasterfrom
jordan/misc-refactors-20260220

Conversation

@Jimbo4350
Copy link
Contributor

Changelog

- description: |
    Misc refactors
# uncomment types applicable to the change:
  type:
  - refactoring

Context

Additional context for the PR goes here. If the PR fixes a particular issue please provide a link to the issue.

How to trust this PR

Highlight important bits of the PR that will make the review faster. If there are commands the reviewer can run to observe the new behavior, describe them.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff

pUrl previously called 'fromMaybe (error "Url longer than 64 bytes")', which
crashes the process when the user supplies a URL longer than 64 bytes.
Restructure to use Opt.option with a custom ReadM that calls Opt.readerError,
so an invalid URL produces a clean optparse-applicative parse failure with a
useful message.
hprop_lovelace_reader: round-trips arbitrary Word64 values through
parseLovelace, and asserts that negative values and overflow (> Word64 max)
are rejected.

hprop_url_reader: confirms that pUrl accepts URLs of 64 bytes or fewer and
returns Nothing (clean parse failure, not a crash) for URLs longer than 64
bytes, exercising the readerError path added in the previous commit.

Also adds optparse-applicative-fork to the cardano-cli-test build-depends so
the parser test can run execParserPure.
urlStr <- readerAsk
let urlText = Text.pack urlStr
maybe (Opt.readerError $ "URL must be 64 bytes or fewer, got: " <> urlStr) pure $
L.textToUrl 128 urlText
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the message says 64, but you're checking for maximum length 128

import qualified Hedgehog.Range as Gen
import qualified Hedgehog.Range as Range
import Options.Applicative (defaultPrefs, execParserPure, getParseResult, info)
import qualified Text.Parsec as Parsec
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Cardano.Api.Parser.Text instead. There are few convenience functions, which could be useful for you.

Copy link
Contributor

@carbolymer carbolymer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branches off in October. Needs rebase.

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.

2 participants