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

refactor out some panics in CedarProto #557

Merged
merged 1 commit into from
Feb 28, 2025
Merged

Conversation

cdisselkoen
Copy link
Contributor

Refactors out some panics in CedarProto. Specifically, the Protobuf parser now gracefully fails (rather than panicking) when encountering:

  • unknown extension type (in a schema)
  • ip() or decimal() argument that fails to parse
  • expression of an unsupported variant (ie not a restricted expression) where a Value is expected

Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
@@ -61,6 +61,12 @@ def map {α β} (f : α → β) : Qualified α → Qualified β
| optional a => optional (f a)
| required a => required (f a)

def transpose {α ε} : Qualified (Except ε α) → Except ε (Qualified α)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I'm uncertain if we need this function here. Intuitively,

let attrs ← attrs.toList.mapM λ (k,v) => do
    let v ← v.map ProtoType.toCedarType |>.transpose
    .ok (k, v)

can be written like

let attrs ← attrs.toList.mapM λ (k,q) => do
    let t ← ProtoType.toCedarType q.getType
    .ok (k, q.map ∘ Function.const t)

Or we can write this function as q.getType.map fun t1 => q.map ∘ Function.const t1

Copy link
Contributor

Choose a reason for hiding this comment

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

Syntactically correct version:

def transpose {α ε} (q : Qualified (Except ε α)) : Except ε (Qualified α) :=
  q.getType.map ((q.map ∘ Function.const _) ·)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I acknowledge you're correct, but I find that harder to read; anyone else have thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

The current definition seems more readable to me. I don't know what q.getType or Function.const mean so I guess some familiarity with those methods is needed.

Copy link
Contributor

@shaobo-he-aws shaobo-he-aws left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -61,6 +61,12 @@ def map {α β} (f : α → β) : Qualified α → Qualified β
| optional a => optional (f a)
| required a => required (f a)

def transpose {α ε} : Qualified (Except ε α) → Except ε (Qualified α)
Copy link
Contributor

Choose a reason for hiding this comment

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

The current definition seems more readable to me. I don't know what q.getType or Function.const mean so I guess some familiarity with those methods is needed.

@cdisselkoen cdisselkoen merged commit e2dafd3 into main Feb 28, 2025
6 checks passed
@cdisselkoen cdisselkoen deleted the cdisselkoen/fewer-panics branch February 28, 2025 20:30
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.

3 participants